Class: Chemlab::Component::DSL
- Inherits:
-
Object
- Object
- Chemlab::Component::DSL
- Defined in:
- lib/chemlab/component.rb
Overview
DSL for both components and resources.
Instance Method Summary collapse
-
#attribute(name) ⇒ Object
An attribute to define for a component or resource.
-
#initialize(base) ⇒ DSL
constructor
A new instance of DSL.
Constructor Details
#initialize(base) ⇒ DSL
Returns a new instance of DSL.
100 101 102 |
# File 'lib/chemlab/component.rb', line 100 def initialize(base) @base = base end |
Instance Method Details
#attribute(name) ⇒ Object
An attribute to define for a component or resource
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/chemlab/component.rb', line 105 def attribute(name) @base.module_eval do attr_writer(name) default_value = block_given? ? yield : nil define_singleton_method(name) do |value = nil| instance_variable_get("@#{name}") || instance_variable_set( "@#{name}", value || default_value ) end end end |