diff --git a/ftl-serializer.gemspec b/ftl-serializer.gemspec index d229c06..caf41de 100644 --- a/ftl-serializer.gemspec +++ b/ftl-serializer.gemspec @@ -33,10 +33,10 @@ Gem::Specification.new do |spec| spec.require_paths = ["lib"] - spec.add_dependency "railties", ">= 5" spec.add_dependency "activesupport", ">= 5" spec.add_dependency "oj", '>= 2' + spec.add_development_dependency "railties", ">= 5" spec.add_development_dependency "rake", "~> 10.0" spec.add_development_dependency "rspec", "~> 3.0" spec.add_development_dependency "pry" diff --git a/lib/ftl-serializer.rb b/lib/ftl-serializer.rb index d0304f7..cb93513 100644 --- a/lib/ftl-serializer.rb +++ b/lib/ftl-serializer.rb @@ -2,7 +2,7 @@ require "ftl/version" require "ftl/serializer" -require "ftl/railtie" +require "ftl/railtie" if defined?(Rails) require "ftl/errors" require "ftl/configuration" require "ftl/serializer/base" diff --git a/lib/ftl/railtie.rb b/lib/ftl/railtie.rb index 7298149..3d39da2 100644 --- a/lib/ftl/railtie.rb +++ b/lib/ftl/railtie.rb @@ -13,20 +13,7 @@ class Railtie < Rails::Railtie end ftl_reloader = app.config.file_watcher.new([], reload_paths) do - FTL::Configuration.serializer_paths.map do |path| - Dir.glob("#{path}/**/*.rb").each do |file| - begin - if Rails.env.development? || Rails.env.test? - load file - else - require file - end - rescue => e - warn "can't load '#{file}' file (#{e.message})!" - end - end - end - + FTL::Serializer.load_from_configured_paths FTL::Serializer.bootstrap! end diff --git a/lib/ftl/serializer.rb b/lib/ftl/serializer.rb index f77b20d..ff68d26 100644 --- a/lib/ftl/serializer.rb +++ b/lib/ftl/serializer.rb @@ -12,6 +12,22 @@ def self.registered_serializers @serializers end + def self.load_from_configured_paths + FTL::Configuration.serializer_paths.map do |path| + Dir.glob("#{path}/**/*.rb").each do |file| + begin + if defined?(Rails) && (Rails.env.development? || Rails.env.test?) + load file + else + require file + end + rescue => e + warn "can't load '#{file}' file (#{e.message})!" + end + end + end + end + def self.bootstrap! return nil unless @serializers @serializers.each do |klass| diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b47ef7c..21a324e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,6 +2,7 @@ require "bundler/setup" require "ftl-serializer" +require "ftl/railtie" FTL::Configuration.serializer_paths = ["spec/ftl/test_examples"] require 'ftl/test_examples/basic_serializer' require 'active_support/testing/time_helpers'