Class: Reactive::MetaModel::ActiveRecordModel
- Inherits:
-
Model
- Object
- Model
- Reactive::MetaModel::ActiveRecordModel
show all
- Defined in:
- lib/activerecord_meta_model.rb
Defined Under Namespace
Classes: Association, Column
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of ActiveRecordModel.
68
69
70
71
|
# File 'lib/activerecord_meta_model.rb', line 68
def initialize(model)
@model = model
@name = model.to_s.demodulize.underscore
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
64
65
66
|
# File 'lib/activerecord_meta_model.rb', line 64
def name
@name
end
|
Instance Method Details
#associations ⇒ Object
85
86
87
|
# File 'lib/activerecord_meta_model.rb', line 85
def associations
belong_tos + has_ones + has_manys
end
|
#attribute(name) ⇒ Object
97
98
99
|
# File 'lib/activerecord_meta_model.rb', line 97
def attribute(name)
attributes.find {|attribute| attribute.name == name.to_sym}
end
|
#attributes ⇒ Object
93
94
95
|
# File 'lib/activerecord_meta_model.rb', line 93
def attributes
columns + associations
end
|
#belong_tos ⇒ Object
81
82
83
|
# File 'lib/activerecord_meta_model.rb', line 81
def belong_tos
@belong_tos ||= @model.reflect_on_all_associations(:belongs_to).map {|association| Association.new(association)}
end
|
#columns ⇒ Object
89
90
91
|
# File 'lib/activerecord_meta_model.rb', line 89
def columns
@columns ||= @model.columns.map {|column| Column.new(column)}
end
|
#has_manys ⇒ Object
73
74
75
|
# File 'lib/activerecord_meta_model.rb', line 73
def has_manys
@has_manys ||= @model.reflect_on_all_associations(:has_many).map {|association| Association.new(association)}
end
|
#has_ones ⇒ Object
77
78
79
|
# File 'lib/activerecord_meta_model.rb', line 77
def has_ones
@has_ones ||= @model.reflect_on_all_associations(:has_one).map {|association| Association.new(association)}
end
|