Class: Adminable::FieldCollector
- Inherits:
-
Object
- Object
- Adminable::FieldCollector
- Defined in:
- lib/adminable/field_collector.rb
Instance Attribute Summary collapse
-
#all ⇒ Array
readonly
Fields from activerecord model.
-
#model ⇒ ActiveRecord::Base
readonly
Activerecord model class.
Instance Method Summary collapse
-
#associations ⇒ Array
Collects fields from model associations.
-
#columns ⇒ Array
Collects fields from model columns.
-
#initialize(model) ⇒ FieldCollector
constructor
A new instance of FieldCollector.
Constructor Details
#initialize(model) ⇒ FieldCollector
Returns a new instance of FieldCollector.
13 14 15 16 |
# File 'lib/adminable/field_collector.rb', line 13 def initialize(model) @model = model @all ||= columns + associations end |
Instance Attribute Details
#all ⇒ Array (readonly)
Returns fields from activerecord model.
10 11 12 |
# File 'lib/adminable/field_collector.rb', line 10 def all @all end |
#model ⇒ ActiveRecord::Base (readonly)
Returns activerecord model class.
7 8 9 |
# File 'lib/adminable/field_collector.rb', line 7 def model @model end |
Instance Method Details
#associations ⇒ Array
Collects fields from model associations
30 31 32 33 34 35 36 |
# File 'lib/adminable/field_collector.rb', line 30 def associations @associations ||= [].tap do |fields| @model.reflect_on_all_associations.each do |association| fields << resolve(association.macro, association.name) end end end |
#columns ⇒ Array
Collects fields from model columns
20 21 22 23 24 25 26 |
# File 'lib/adminable/field_collector.rb', line 20 def columns @columns ||= [].tap do |fields| @model.columns.reject { |a| a.name.match(/_id$/) }.each do |column| fields << resolve(column.type, column.name) end end end |