Class: Material::Components::Component

Inherits:
Object
  • Object
show all
Defined in:
lib/material/concerns/components.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(**options, &block)
  @options = {}
  configure(**options, &block)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



56
57
58
# File 'lib/material/concerns/components.rb', line 56

def options
  @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?
  options.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