Module: CouchPillow::AttributeDirective

Included in:
Document
Defined in:
lib/couchpillow/directives/attribute.rb

Instance Method Summary collapse

Instance Method Details

#attribute(attr, &block) ⇒ Object

Declares a new Attribute



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/couchpillow/directives/attribute.rb', line 7

def attribute attr, &block
  attr = attr.to_s.to_sym
  new_attr = Attribute.new(attr)
  attributes[attr] = new_attr

  # Define accessor methods
  define_method(attr) do
    @data[attr]
  end
  define_method("#{attr}=") do |val|
    @data[attr] = val
  end

  new_attr.instance_eval &block if block

  new_attr
end

#attributesObject



26
27
28
# File 'lib/couchpillow/directives/attribute.rb', line 26

def attributes
  @attributes ||= {}
end