Class: Chemlab::Resource::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/chemlab/resource.rb

Instance Method Summary collapse

Constructor Details

#initialize(base) ⇒ DSL

Returns a new instance of DSL.



149
150
151
# File 'lib/chemlab/resource.rb', line 149

def initialize(base)
  @base = base
end

Instance Method Details

#attribute(name, &block) ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/chemlab/resource.rb', line 153

def attribute(name, &block)
  @base.module_eval do
    attr_writer(name)

    define_method(name) do
      instance_variable_get("@#{name}") ||
        instance_variable_set(
          "@#{name}",
          populate_attribute(name, block))
    end
  end
end