Module: CouchRestAdapter::AttributeMethod

Included in:
Base
Defined in:
lib/couch_rest_adapter/attribute_method.rb

Instance Method Summary collapse

Instance Method Details

#attribute_methodsObject



31
32
33
# File 'lib/couch_rest_adapter/attribute_method.rb', line 31

def attribute_methods
  _attributes.keys.map{ |attr| [attr, "#{attr}="] }.flatten
end

#base_idObject



35
36
37
# File 'lib/couch_rest_adapter/attribute_method.rb', line 35

def base_id
  File.basename self['_id']
end

#method_without_equals(method_name) ⇒ Object



23
24
25
# File 'lib/couch_rest_adapter/attribute_method.rb', line 23

def method_without_equals method_name
  method_name.to_s.sub(/=$/,'').to_sym
end

#read_value(method_name) ⇒ Object



8
9
10
11
12
13
# File 'lib/couch_rest_adapter/attribute_method.rb', line 8

def read_value method_name
  singleton_class.class_eval do
    define_method(method_name) { self[method_name] }
  end
  send(method_name)
end

#read_write(method, value = nil) ⇒ Object



4
5
6
# File 'lib/couch_rest_adapter/attribute_method.rb', line 4

def read_write method, value = nil
  writer?(method) ? write_value(method, value) : read_value(method)
end

#write_value(method_name, value) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/couch_rest_adapter/attribute_method.rb', line 15

def write_value method_name, value
  base_method_name = method_without_equals(method_name)
  singleton_class.class_eval do
    define_method(method_name) { |v| self[base_method_name] = v }
  end
  send(method_name, value)
end

#writer?(method_name) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/couch_rest_adapter/attribute_method.rb', line 27

def writer? method_name
  method_name =~ /=$/
end