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.



60
61
62
63
# File 'lib/material/concerns/components.rb', line 60

def initialize(**options, &block)
  @options = {}
  configure(**options, &block)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



58
59
60
# File 'lib/material/concerns/components.rb', line 58

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