Class: Wallaby::ActiveRecord::ModelDecorator::FieldsBuilder
- Inherits:
-
Object
- Object
- Wallaby::ActiveRecord::ModelDecorator::FieldsBuilder
- Defined in:
- lib/adapters/wallaby/active_record/model_decorator/fields_builder.rb,
lib/adapters/wallaby/active_record/model_decorator/fields_builder/sti_builder.rb,
lib/adapters/wallaby/active_record/model_decorator/fields_builder/association_builder.rb,
lib/adapters/wallaby/active_record/model_decorator/fields_builder/polymorphic_builder.rb
Overview
To build the metadata for fields
Defined Under Namespace
Classes: AssociationBuilder, PolymorphicBuilder, StiBuilder
Instance Method Summary collapse
-
#association_fields ⇒ Hash<String, Hash>
A hash for association fields (e.g. belongs_to / has_one / has_many / has_and_belongs_to_many).
-
#general_fields ⇒ Hash<String, Hash>
A hash for general fields.
-
#initialize(model_class) ⇒ FieldsBuilder
constructor
A new instance of FieldsBuilder.
Constructor Details
#initialize(model_class) ⇒ FieldsBuilder
Returns a new instance of FieldsBuilder.
9 10 11 |
# File 'lib/adapters/wallaby/active_record/model_decorator/fields_builder.rb', line 9 def initialize(model_class) @model_class = model_class end |
Instance Method Details
#association_fields ⇒ Hash<String, Hash>
Returns a hash for association fields (e.g. belongs_to / has_one / has_many / has_and_belongs_to_many).
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/adapters/wallaby/active_record/model_decorator/fields_builder.rb', line 28 def association_fields @association_fields ||= @model_class.reflections.each_with_object({}) do |(name, reflection), fields| = { type: reflection.macro.to_s, # association type label: @model_class.human_attribute_name(name) } association_builder.update(, reflection) polymorphic_builder.update(, reflection) update_general_fields_with() fields[name] = end end |
#general_fields ⇒ Hash<String, Hash>
Returns a hash for general fields.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/adapters/wallaby/active_record/model_decorator/fields_builder.rb', line 14 def general_fields @general_fields ||= @model_class.columns.each_with_object({}) do |column, fields| = { type: to_type(column).freeze, label: @model_class.human_attribute_name(column.name) } sti_builder.update(, column) fields[column.name] = end end |