Class: Pears::Provider::Builder
- Inherits:
-
Object
- Object
- Pears::Provider::Builder
- Defined in:
- lib/pears/provider/builder.rb
Class Method Summary collapse
-
.enable_provider(provider, yielder: false) ⇒ Object
Evil meta programming.
Instance Method Summary collapse
- #freeze_layers ⇒ Object
-
#initialize(subject) ⇒ Builder
constructor
A new instance of Builder.
- #subject_name ⇒ Object
Constructor Details
#initialize(subject) ⇒ Builder
Returns a new instance of Builder.
45 46 47 |
# File 'lib/pears/provider/builder.rb', line 45 def initialize(subject) @subject = subject end |
Class Method Details
.enable_provider(provider, yielder: false) ⇒ Object
Evil meta programming.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/pears/provider/builder.rb', line 7 def self.enable_provider(provider, yielder: false) method_name = provider.name.split('::').last.underscore.to_sym if yielder 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 end |
Instance Method Details
#freeze_layers ⇒ Object
49 50 51 52 53 |
# File 'lib/pears/provider/builder.rb', line 49 def freeze_layers @skip_push = true yield @skip_push = false end |
#subject_name ⇒ Object
55 56 57 |
# File 'lib/pears/provider/builder.rb', line 55 def subject_name @subject.name end |