Class: CouchPotato::Persistence::Properties::PropertyList

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/couch_potato/persistence/properties.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(clazz) ⇒ PropertyList

Returns a new instance of PropertyList.



12
13
14
15
16
# File 'lib/couch_potato/persistence/properties.rb', line 12

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

Instance Attribute Details

#listObject

Returns the value of attribute list.



10
11
12
# File 'lib/couch_potato/persistence/properties.rb', line 10

def list
  @list
end

Instance Method Details

#<<(property) ⇒ Object



22
23
24
25
# File 'lib/couch_potato/persistence/properties.rb', line 22

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

#each(&block) ⇒ Object



18
19
20
# File 'lib/couch_potato/persistence/properties.rb', line 18

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

#find_property(name) ⇒ Object



27
28
29
# File 'lib/couch_potato/persistence/properties.rb', line 27

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

#inherited_propertiesObject



36
37
38
39
40
41
42
43
44
# File 'lib/couch_potato/persistence/properties.rb', line 36

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

XXX



32
33
34
# File 'lib/couch_potato/persistence/properties.rb', line 32

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