lib/pears/provider/builder.rb in pears-0.1.4 vs lib/pears/provider/builder.rb in pears-0.2.0

- old
+ new

@@ -5,17 +5,27 @@ class Builder # Evil meta programming. def self.enable_provider(provider, yielder: false) method_name = provider.name.split('::').last.underscore.to_sym if yielder - define_method(method_name) do |*args, &block| + define_method(method_name) do |*args, **opts, &block| + # Skip if Rails environment should not use this perticular setting + if defined?(Rails) + return if Array.wrap(opts[:skip_env]).include?(Rails.env.to_sym) + end + pr = provider.new(builder: self, &block) push pr pr end else define_method(method_name) do |*args, **opts, &block| + # Skip if Rails environment should not use this perticular setting + if defined?(Rails) + return if Array.wrap(opts[:skip_env]).include?(Rails.env.to_sym) + end + pr = provider.new(*args, **opts, &block) push pr pr end end @@ -23,9 +33,13 @@ # define Providers enable_provider LocalFile enable_provider RemoteFile enable_provider Subscription, yielder: true + + if defined?(Rails) == "constant" + enable_provider RailsConfig + end delegate :name, to: :subject def initialize(subject) @subject = subject