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.
60 61 62 63 |
# File 'lib/material/concerns/components.rb', line 60 def initialize(**, &block) @options = {} configure(**, &block) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
58 59 60 |
# File 'lib/material/concerns/components.rb', line 58 def @options end |
Instance Method Details
#configure(**opts, &block) ⇒ Object
73 74 75 76 |
# File 'lib/material/concerns/components.rb', line 73 def configure(**opts, &block) @value = block if block_given? .merge!(**opts) end |
#initialize_copy(other) ⇒ Object
78 79 80 81 82 |
# File 'lib/material/concerns/components.rb', line 78 def initialize_copy(other) super @options = @options.dup @value = @value.dup if @value.present? end |
#value_for(object) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/material/concerns/components.rb', line 65 def value_for(object) value = object.instance_eval(&@value) if @value.respond_to?(:call) return value.dup if CLASSES_TO_DUPLICATE.any? { |klass| value.is_a?(klass) } value end |