Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove railtie as a dependency if you're not running Rails #3

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ftl-serializer.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion lib/ftl-serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
15 changes: 1 addition & 14 deletions lib/ftl/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 16 additions & 0 deletions lib/ftl/serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down