Class: Common::Base
- Inherits:
-
Object
show all
- Extended by:
- ActiveModel::Naming
- Includes:
- ActiveModel::Serialization, Comparable
- Defined in:
- lib/common/models/base.rb
Overview
This is a base serialization class
Direct Known Subclasses
AllTriageTeams, Apps::Responses::Response, Attachment, BGSDependents::Base, BenefitsEducation::Amendment, BenefitsEducation::Enrollment, BenefitsEducation::Entitlement, BenefitsEducation::Response, Caseflow::Responses::Caseflow, Category, EVSS::IntentToFile::IntentToFile, EVSS::Letters::BenefitInformation, EVSS::Letters::Letter, EVSS::Letters::MilitaryService, EVSS::Response, EVSSClaimDocument, EligibleDataClass, ExtractStatus, Folder, Forms::Responses::Response, IHub::Appointments::Response, Lighthouse::Facilities::Facility, Lighthouse::Facilities::NearbyFacility, Lighthouse::Facilities::NearbyResponse, Lighthouse::Facilities::Response, Lighthouse::Facilities::V1::Response, LighthouseDocument, MDOT::Response, Message, MessageSearch, MessageThread, MessagingPreference, PagerDuty::Response, PaymentHistory, PowerOfAttorney, Preneeds::AttachmentType, Preneeds::Cemetery, Preneeds::MilitaryRankInput, Preneeds::ReceiveApplication, Prescription, PrescriptionPreference, Search::ResultsResponse, Tracking, TriageTeam, VAProfile::Response
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(init_attributes = {}) ⇒ Base
Returns a new instance of Base.
51
52
53
54
55
56
|
# File 'lib/common/models/base.rb', line 51
def initialize(init_attributes = {})
super(init_attributes[:data] || init_attributes)
@metadata = init_attributes[:metadata] || {}
@errors_hash = init_attributes[:errors] || {}
@original_attributes = attributes
end
|
Instance Attribute Details
#errors_hash ⇒ Object
Returns the value of attribute errors_hash.
14
15
16
|
# File 'lib/common/models/base.rb', line 14
def errors_hash
@errors_hash
end
|
Returns the value of attribute metadata.
14
15
16
|
# File 'lib/common/models/base.rb', line 14
def metadata
@metadata
end
|
Class Method Details
.default_sort ⇒ Object
37
38
39
40
41
42
|
# File 'lib/common/models/base.rb', line 37
def default_sort
@default_sort ||= begin
sortable_attributes
@default_sort
end
end
|
.filterable_attributes ⇒ Object
44
45
46
47
48
|
# File 'lib/common/models/base.rb', line 44
def filterable_attributes
@filterable_attributes ||= attribute_set.map do |attribute|
[attribute.name.to_s, attribute.options[:filterable]] if attribute.options[:filterable]
end.compact.to_h.with_indifferent_access
end
|
.max_per_page(value = nil) ⇒ Object
21
22
23
|
# File 'lib/common/models/base.rb', line 21
def max_per_page(value = nil)
@max_per_page ||= value || 100
end
|
.per_page(value = nil) ⇒ Object
17
18
19
|
# File 'lib/common/models/base.rb', line 17
def per_page(value = nil)
@per_page ||= value || 10
end
|
.sortable_attributes ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/common/models/base.rb', line 25
def sortable_attributes
@sortable_attributes ||= attribute_set.map do |attribute|
next unless attribute.options[:sortable]
sortable = attribute.options[:sortable].is_a?(Hash) ? attribute.options[:sortable] : { order: 'ASC' }
if sortable[:default]
@default_sort ||= sortable[:order] == 'DESC' ? "-#{attribute.name}" : attribute.name.to_s
end
[attribute.name.to_s, sortable[:order]]
end.compact.to_h.with_indifferent_access
end
|
Instance Method Details
#changed ⇒ Object
62
63
64
|
# File 'lib/common/models/base.rb', line 62
def changed
attributes.map { |k, v| k if @original_attributes[k] != v }.compact
end
|
#changed? ⇒ Boolean
58
59
60
|
# File 'lib/common/models/base.rb', line 58
def changed?
changed.any?
end
|
#changes ⇒ Object
66
67
68
|
# File 'lib/common/models/base.rb', line 66
def changes
changed.map { |k, _v| [k, [@original_attributes[k], attributes[k]]] }.to_h
end
|