Class: Wallaby::ModelDecorator
- Inherits:
-
Object
- Object
- Wallaby::ModelDecorator
- Defined in:
- lib/interfaces/wallaby/model_decorator.rb
Overview
Model Decorator interface, designed to maintain metadata information for all the fields coming from data source (database/api)
Direct Known Subclasses
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
-
#form_label_of(field_name) ⇒ String
Form label for a given field.
-
#form_metadata_of(field_name) ⇒ Hash
Form metadata information for a given field.
-
#form_type_of(field_name) ⇒ String, Symbol
Form type for a given field.
-
#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
-
#index_label_of(field_name) ⇒ String
Index label for a given field.
-
#index_metadata_of(field_name) ⇒ Hash
Index metadata information for a given field.
-
#index_type_of(field_name) ⇒ String, Symbol
Index type for a given field.
-
#initialize(model_class) ⇒ ModelDecorator
constructor
A new instance of ModelDecorator.
-
#label_of(field_name) ⇒ String
Label for a given field.
-
#metadata_of(field_name) ⇒ Hash
Metadata information for a given field.
-
#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
-
#show_label_of(field_name) ⇒ String
Show label for a given field.
-
#show_metadata_of(field_name) ⇒ Hash
Show metadata information for a given field.
-
#show_type_of(field_name) ⇒ String, Symbol
Show type for a given field.
-
#type_of(field_name) ⇒ String, Symbol
Type for a given field.
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.
123 124 125 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 123 def form_field_names @form_field_names ||= reposition form_fields.keys, primary_key end |
#index_field_names ⇒ Array
Returns field names of index page.
59 60 61 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 59 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.
91 92 93 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 91 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.
143 144 145 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 143 def filters @filters ||= ::ActiveSupport::HashWithIndifferentAccess.new end |
#form_active_errors(_resource) ⇒ Hash
Returns errors.
148 149 150 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 148 def form_active_errors(_resource) raise NotImplemented end |
#form_fields ⇒ Hash
Returns metadata information for all fields that would be used on form page.
112 113 114 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 112 def form_fields raise NotImplemented end |
#form_fields=(fields) ⇒ Object
118 119 120 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 118 def form_fields=(fields) @form_fields = ::ActiveSupport::HashWithIndifferentAccess.new fields end |
#form_label_of(field_name) ⇒ String
Returns form label for a given field.
133 134 135 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 133 def form_label_of(field_name) (field_name)[:label] end |
#form_metadata_of(field_name) ⇒ Hash
Returns form metadata information for a given field.
128 129 130 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 128 def (field_name) form_fields[field_name] || {} end |
#form_type_of(field_name) ⇒ String, Symbol
Returns form type for a given field.
138 139 140 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 138 def form_type_of(field_name) validate_presence_of (field_name)[:type] end |
#guess_title(_resource) ⇒ String
Returns title of given resource.
159 160 161 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 159 def guess_title(_resource) raise NotImplemented end |
#index_fields ⇒ Hash
Returns metadata information for all fields that would be used on index page.
48 49 50 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 48 def index_fields raise NotImplemented end |
#index_fields=(fields) ⇒ Object
54 55 56 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 54 def index_fields=(fields) @index_fields = ::ActiveSupport::HashWithIndifferentAccess.new fields end |
#index_label_of(field_name) ⇒ String
Returns index label for a given field.
69 70 71 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 69 def index_label_of(field_name) (field_name)[:label] end |
#index_metadata_of(field_name) ⇒ Hash
Returns index metadata information for a given field.
64 65 66 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 64 def (field_name) index_fields[field_name] || {} end |
#index_type_of(field_name) ⇒ String, Symbol
Returns index type for a given field.
74 75 76 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 74 def index_type_of(field_name) validate_presence_of (field_name)[:type] end |
#label_of(field_name) ⇒ String
Returns label for a given field.
37 38 39 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 37 def label_of(field_name) (field_name)[:label] end |
#metadata_of(field_name) ⇒ Hash
Returns metadata information for a given field.
32 33 34 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 32 def (field_name) fields[field_name] || {} end |
#primary_key ⇒ String
Returns primary key.
153 154 155 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 153 def primary_key raise NotImplemented end |
#resources_name ⇒ String
Returns resources name mapped from model class.
164 165 166 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 164 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.
80 81 82 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 80 def show_fields raise NotImplemented end |
#show_fields=(fields) ⇒ Object
86 87 88 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 86 def show_fields=(fields) @show_fields = ::ActiveSupport::HashWithIndifferentAccess.new fields end |
#show_label_of(field_name) ⇒ String
Returns show label for a given field.
101 102 103 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 101 def show_label_of(field_name) (field_name)[:label] end |
#show_metadata_of(field_name) ⇒ Hash
Returns show metadata information for a given field.
96 97 98 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 96 def (field_name) show_fields[field_name] || {} end |
#show_type_of(field_name) ⇒ String, Symbol
Returns show type for a given field.
106 107 108 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 106 def show_type_of(field_name) validate_presence_of (field_name)[:type] end |
#type_of(field_name) ⇒ String, Symbol
Returns type for a given field.
42 43 44 |
# File 'lib/interfaces/wallaby/model_decorator.rb', line 42 def type_of(field_name) validate_presence_of (field_name)[:type] end |