Module: QbwcRequests::OrderedFields
- Included in:
- Base
- Defined in:
- lib/qbwc_requests/ordered_fields.rb
Defined Under Namespace
Modules: ClassMethods
Classes: SubModelsValidator
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.included(base) ⇒ Object
57
58
59
60
61
62
63
|
# File 'lib/qbwc_requests/ordered_fields.rb', line 57
def self.included(base)
base.extend(ActiveModel::Naming)
base.include(ActiveModel::Validations)
base.include(ActiveModel::Conversion)
base.extend(ClassMethods)
base.validates_with(SubModelsValidator)
end
|
Instance Method Details
#ordered_fields ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/qbwc_requests/ordered_fields.rb', line 65
def ordered_fields
return {} if self.class.attr_order.blank?
new_hash = {}
for attribute in self.class.attr_order
value = send(attribute)
if value.present?
if value.kind_of?(Array)
result = value.map { |item | item.respond_to?(:ordered_fields) ? item.ordered_fields : item }
else
result = value.respond_to?(:ordered_fields) ? value.ordered_fields : value
end
new_hash[attribute] = result
end
end
new_hash
end
|