Class: Reactive::MetaModel::Model

Inherits:
Object
  • Object
show all
Defined in:
lib/reactive-core/meta_model.rb

Instance Method Summary collapse

Instance Method Details

#add_observer(object) ⇒ Object

registers the passed object as an observer. the object may receive notification through these methods:

(see ActiveRecord::Callbacks)

Note that each of these methods will receive a unique argument which is the record that has been treated.



49
50
# File 'lib/reactive-core/meta_model.rb', line 49

def add_observer(object)
end

#associationsObject



68
69
70
# File 'lib/reactive-core/meta_model.rb', line 68

def associations
  @attributes.select {|name,value| value.is_a? Association}
end

#attribute(name) ⇒ Object



80
81
82
# File 'lib/reactive-core/meta_model.rb', line 80

def attribute(name)
  @attributes[name.to_sym]
end

#attributesObject



76
77
78
# File 'lib/reactive-core/meta_model.rb', line 76

def attributes
  @attributes.values
end

#belong_tosObject



64
65
66
# File 'lib/reactive-core/meta_model.rb', line 64

def belong_tos
  @attributes.select {|name,value| value.is_a?(Association) && value.kind == :belongs_to}
end

#columnsObject



72
73
74
# File 'lib/reactive-core/meta_model.rb', line 72

def columns
  @attributes.select {|name,value| value.is_a? Column}
end

#cooked_attributesObject



84
85
86
87
# File 'lib/reactive-core/meta_model.rb', line 84

def cooked_attributes
  association_columns = associations.collect {|assoc| assoc.columns}.flatten
  associations + columns.reject {|col| association_columns.include?(col.name) || col.primary? }
end

#delete_observer(object) ⇒ Object

remove the object from the registered observers



53
54
# File 'lib/reactive-core/meta_model.rb', line 53

def delete_observer(object)
end

#has_manysObject



56
57
58
# File 'lib/reactive-core/meta_model.rb', line 56

def has_manys
  @attributes.select {|name,value| value.is_a?(Association) && value.kind == :has_many}
end

#has_onesObject



60
61
62
# File 'lib/reactive-core/meta_model.rb', line 60

def has_ones
  @attributes.select {|name,value| value.is_a?(Association) && value.kind == :has_one}
end