Class: Material::Components::Component
- Inherits:
-
Object
- Object
- Material::Components::Component
- Defined in:
- lib/material/concerns/components.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #configure(**opts, &block) ⇒ Object
-
#initialize(**options, &block) ⇒ Component
constructor
A new instance of Component.
- #initialize_copy(other) ⇒ Object
- #value_for(object) ⇒ Object
Constructor Details
#initialize(**options, &block) ⇒ Component
Returns a new instance of Component.
58 59 60 61 |
# File 'lib/material/concerns/components.rb', line 58 def initialize(**, &block) @options = {} configure(**, &block) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
56 57 58 |
# File 'lib/material/concerns/components.rb', line 56 def @options end |
Instance Method Details
#configure(**opts, &block) ⇒ Object
67 68 69 70 |
# File 'lib/material/concerns/components.rb', line 67 def configure(**opts, &block) @value = block if block_given? .merge!(**opts) end |
#initialize_copy(other) ⇒ Object
72 73 74 75 76 |
# File 'lib/material/concerns/components.rb', line 72 def initialize_copy(other) super @options = @options.dup @value = @value.dup if @value.present? end |
#value_for(object) ⇒ Object
63 64 65 |
# File 'lib/material/concerns/components.rb', line 63 def value_for(object) object.instance_eval(&@value).dup if @value.respond_to?(:call) end |