Class: SimplyCouch::Model::Persistence::Properties::PropertyList

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/simply_couch/model/persistence.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(clazz) ⇒ PropertyList

Returns a new instance of PropertyList.



80
81
82
83
84
# File 'lib/simply_couch/model/persistence.rb', line 80

def initialize(clazz)
  @clazz = clazz
  @list = []
  @hash = {}
end

Instance Attribute Details

#listObject

Returns the value of attribute list.



78
79
80
# File 'lib/simply_couch/model/persistence.rb', line 78

def list
  @list
end

Instance Method Details

#<<(property) ⇒ Object



87
# File 'lib/simply_couch/model/persistence.rb', line 87

def <<(property); @hash[property.name] = property; @list << property; end

#each(&block) ⇒ Object



86
# File 'lib/simply_couch/model/persistence.rb', line 86

def each(&block); (list + inherited_properties).each(&block); end

#find_property(name) ⇒ Object



88
# File 'lib/simply_couch/model/persistence.rb', line 88

def find_property(name); @hash[name] || @clazz.superclass.properties.find_property(name); end

#inherited_propertiesObject



91
92
93
94
95
96
97
98
99
# File 'lib/simply_couch/model/persistence.rb', line 91

def inherited_properties
  superclazz = @clazz.superclass
  properties = []
  while superclazz && superclazz.respond_to?(:properties)
    properties << superclazz.properties.list
    superclazz = superclazz.superclass
  end
  properties.flatten
end

#inspectObject



89
# File 'lib/simply_couch/model/persistence.rb', line 89

def inspect; list.map(&:name).inspect; end