Class: Alba::ConditionalAttribute Private
- Inherits:
-
Object
- Object
- Alba::ConditionalAttribute
- Defined in:
- lib/alba/conditional_attribute.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Represents attribute with ‘if` option
Instance Method Summary collapse
-
#initialize(body:, condition:) ⇒ ConditionalAttribute
constructor
private
A new instance of ConditionalAttribute.
-
#with_passing_condition(resource:, object: nil) ⇒ Alba::REMOVE_KEY, Object
private
Returns attribute body if condition passes.
Constructor Details
#initialize(body:, condition:) ⇒ ConditionalAttribute
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of ConditionalAttribute.
13 14 15 16 |
# File 'lib/alba/conditional_attribute.rb', line 13 def initialize(body:, condition:) @body = body @condition = condition end |
Instance Method Details
#with_passing_condition(resource:, object: nil) ⇒ Alba::REMOVE_KEY, Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns attribute body if condition passes
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/alba/conditional_attribute.rb', line 23 def with_passing_condition(resource:, object: nil) return Alba::REMOVE_KEY unless condition_passes?(resource, object) fetched_attribute = yield(@body) return fetched_attribute unless with_two_arity_proc_condition return Alba::REMOVE_KEY unless resource.instance_exec(object, objectize(fetched_attribute), &@condition) fetched_attribute end |