Class: Moonshine::Filter
- Inherits:
-
Object
- Object
- Moonshine::Filter
- Defined in:
- lib/moonshine/filter.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#params ⇒ Object
Returns the value of attribute params.
Instance Method Summary collapse
- #execute(subject) ⇒ Object
-
#initialize(name, **options, &block) ⇒ Filter
constructor
A new instance of Filter.
- #to_execute? ⇒ Boolean
Constructor Details
#initialize(name, **options, &block) ⇒ Filter
Returns a new instance of Filter.
6 7 8 9 10 |
# File 'lib/moonshine/filter.rb', line 6 def initialize(name, **, &block) @name = name [:call] ||= block || name @options = end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/moonshine/filter.rb', line 4 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/moonshine/filter.rb', line 4 def @options end |
#params ⇒ Object
Returns the value of attribute params.
4 5 6 |
# File 'lib/moonshine/filter.rb', line 4 def params @params end |
Instance Method Details
#execute(subject) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/moonshine/filter.rb', line 12 def execute(subject) return subject unless to_execute? if [:as_boolean] subject.send([:call]) else if [:call].is_a? Proc [:call].call(subject, args) else subject.send([:call], args) end end end |
#to_execute? ⇒ Boolean
25 26 27 |
# File 'lib/moonshine/filter.rb', line 25 def to_execute? !!default end |