Class: Wallaby::ModelDecorator
- Inherits:
-
Object
- Object
- Wallaby::ModelDecorator
- Includes:
- FieldHelpers
- Defined in:
- lib/interfaces/wallaby/model_decorator.rb,
lib/interfaces/wallaby/model_decorator/field_helpers.rb
Direct Known Subclasses
Defined Under Namespace
Modules: FieldHelpers
Instance Attribute Summary collapse
-
#field_names ⇒ Array
Field names.
-
#form_field_names ⇒ Array
Field names of form page.
-
#index_field_names ⇒ Array
Field names of index page.
-
#model_class ⇒ Object
readonly
Returns the value of attribute model_class.
-
#show_field_names ⇒ Array
Field names of show page.
Instance Method Summary collapse
-
#fields ⇒ Hash
Metadata information for all fields that index/show/form will copy.
- #fields=(fields) ⇒ Object
-
#filters ⇒ Hash
Custom filters.
-
#form_active_errors(_resource) ⇒ Hash
Errors.
-
#form_fields ⇒ Hash
Metadata information for all fields that would be used on form page.
- #form_fields=(fields) ⇒ Object
-
#guess_title(_resource) ⇒ String
Title of given resource.
-
#index_fields ⇒ Hash
Metadata information for all fields that would be used on index page.
- #index_fields=(fields) ⇒ Object
-
#initialize(model_class) ⇒ ModelDecorator
constructor
A new instance of ModelDecorator.
-
#primary_key ⇒ String
Primary key.
-
#resources_name ⇒ String
Resources name mapped from model class.
-
#show_fields ⇒ Hash
Metadata information for all fields that would be used on show page.
- #show_fields=(fields) ⇒ Object
Methods included from FieldHelpers
#form_label_of, #form_metadata_of, #form_type_of, #index_label_of, #index_metadata_of, #index_type_of, #label_of, #metadata_of, #show_label_of, #show_metadata_of, #show_type_of, #type_of
Constructor Details
#initialize(model_class) ⇒ ModelDecorator
Returns a new instance of ModelDecorator.
11 12 13 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 11 def initialize(model_class) @model_class = model_class end |
Instance Attribute Details
#field_names ⇒ Array
Returns field names.
27 28 29 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 27 def field_names @field_names ||= reposition fields.keys, primary_key end |
#form_field_names ⇒ Array
Returns field names of form page.
78 79 80 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 78 def form_field_names @form_field_names ||= reposition form_fields.keys, primary_key end |
#index_field_names ⇒ Array
Returns field names of index page.
44 45 46 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 44 def index_field_names @index_field_names ||= reposition index_fields.keys, primary_key end |
#model_class ⇒ Object (readonly)
Returns the value of attribute model_class.
7 8 9 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 7 def model_class @model_class end |
#show_field_names ⇒ Array
Returns field names of show page.
61 62 63 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 61 def show_field_names @show_field_names ||= reposition show_fields.keys, primary_key end |
Instance Method Details
#fields ⇒ Hash
Returns metadata information for all fields that index/show/form will copy.
17 18 19 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 17 def fields raise NotImplemented end |
#fields=(fields) ⇒ Object
22 23 24 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 22 def fields=(fields) @fields = ::ActiveSupport::HashWithIndifferentAccess.new fields end |
#filters ⇒ Hash
Returns custom filters.
83 84 85 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 83 def filters @filters ||= ::ActiveSupport::HashWithIndifferentAccess.new end |
#form_active_errors(_resource) ⇒ Hash
Returns errors.
88 89 90 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 88 def form_active_errors(_resource) raise NotImplemented end |
#form_fields ⇒ Hash
Returns metadata information for all fields that would be used on form page.
67 68 69 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 67 def form_fields raise NotImplemented end |
#form_fields=(fields) ⇒ Object
73 74 75 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 73 def form_fields=(fields) @form_fields = ::ActiveSupport::HashWithIndifferentAccess.new fields end |
#guess_title(_resource) ⇒ String
Returns title of given resource.
99 100 101 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 99 def guess_title(_resource) raise NotImplemented end |
#index_fields ⇒ Hash
Returns metadata information for all fields that would be used on index page.
33 34 35 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 33 def index_fields raise NotImplemented end |
#index_fields=(fields) ⇒ Object
39 40 41 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 39 def index_fields=(fields) @index_fields = ::ActiveSupport::HashWithIndifferentAccess.new fields end |
#primary_key ⇒ String
Returns primary key.
93 94 95 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 93 def primary_key raise NotImplemented end |
#resources_name ⇒ String
Returns resources name mapped from model class.
104 105 106 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 104 def resources_name Map.resources_name_map @model_class end |
#show_fields ⇒ Hash
Returns metadata information for all fields that would be used on show page.
50 51 52 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 50 def show_fields raise NotImplemented end |
#show_fields=(fields) ⇒ Object
56 57 58 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 56 def show_fields=(fields) @show_fields = ::ActiveSupport::HashWithIndifferentAccess.new fields end |