Class: Moonshine::Base
Instance Attribute Summary collapse
-
#chain ⇒ Object
readonly
Returns the value of attribute chain.
-
#params ⇒ Object
Returns the value of attribute params.
-
#subject ⇒ Object
Returns the value of attribute subject.
Instance Method Summary collapse
- #add_filter_to_chain(name, **options, &block) ⇒ Object
-
#initialize(params, subject = nil) ⇒ Base
constructor
A new instance of Base.
- #run ⇒ Object
Methods included from DSL
Constructor Details
#initialize(params, subject = nil) ⇒ Base
Returns a new instance of Base.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/moonshine/base.rb', line 8 def initialize(params, subject = nil) @subject = subject || self.class.default_subject.call @params = params @chain = [] if self.class.default_chain self.class.default_chain.each do |params| add_filter_to_chain(params[:name], params[:options], ¶ms[:block]) end end end |
Instance Attribute Details
#chain ⇒ Object (readonly)
Returns the value of attribute chain.
3 4 5 |
# File 'lib/moonshine/base.rb', line 3 def chain @chain end |
#params ⇒ Object
Returns the value of attribute params.
4 5 6 |
# File 'lib/moonshine/base.rb', line 4 def params @params end |
#subject ⇒ Object
Returns the value of attribute subject.
4 5 6 |
# File 'lib/moonshine/base.rb', line 4 def subject @subject end |
Instance Method Details
#add_filter_to_chain(name, **options, &block) ⇒ Object
19 20 21 |
# File 'lib/moonshine/base.rb', line 19 def add_filter_to_chain(name, **, &block) @chain << Moonshine::Filter.new(name, , &block) end |
#run ⇒ Object
23 24 25 26 27 28 |
# File 'lib/moonshine/base.rb', line 23 def run chain.inject(subject) do |subject, filter| filter.params = params subject = filter.execute(subject) end end |