Class: Location::AddressForm
- Inherits:
-
Object
- Object
- Location::AddressForm
- Includes:
- SuperForm
- Defined in:
- app/models/location/address_form.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
Returns the value of attribute model.
Class Method Summary collapse
- .default_presence_attributes ⇒ Object
- .float_attributes ⇒ Object
- .normalizable_attributes ⇒ Object
- .string_attributes ⇒ Object
Instance Method Summary collapse
- #address_attributes ⇒ Object
- #attribute_normalized?(attr) ⇒ Boolean
- #ensure_valid_normalized_attributes! ⇒ Object
- #normalized_attributes ⇒ Object
- #normalized_attributes=(attributes) ⇒ Object
- #presence ⇒ Object
- #validate_presence_of(attributes) ⇒ Object
Instance Attribute Details
#model ⇒ Object
Returns the value of attribute model.
34 35 36 |
# File 'app/models/location/address_form.rb', line 34 def model @model end |
Class Method Details
.default_presence_attributes ⇒ Object
11 12 13 |
# File 'app/models/location/address_form.rb', line 11 def self.default_presence_attributes %i{postal_code address district} end |
.float_attributes ⇒ Object
19 20 21 |
# File 'app/models/location/address_form.rb', line 19 def self.float_attributes %i{latitude longitude} end |
.normalizable_attributes ⇒ Object
7 8 9 |
# File 'app/models/location/address_form.rb', line 7 def self.normalizable_attributes %i{state city district} end |
.string_attributes ⇒ Object
15 16 17 |
# File 'app/models/location/address_form.rb', line 15 def self.string_attributes %i{postal_code address number complement district city state} end |
Instance Method Details
#address_attributes ⇒ Object
40 41 42 43 |
# File 'app/models/location/address_form.rb', line 40 def address_attributes attributes = %w{postal_code address number complement latitude longitude} values_for_attributes(attributes) end |
#attribute_normalized?(attr) ⇒ Boolean
62 63 64 |
# File 'app/models/location/address_form.rb', line 62 def attribute_normalized?(attr) normalized_attributes.include?(attr) end |
#ensure_valid_normalized_attributes! ⇒ Object
56 57 58 59 60 |
# File 'app/models/location/address_form.rb', line 56 def ensure_valid_normalized_attributes! unless valid_normalized_attributes? raise ::StandardError.new, "Invalid normalizable attributes" end end |
#normalized_attributes ⇒ Object
50 51 52 53 54 |
# File 'app/models/location/address_form.rb', line 50 def normalized_attributes @normalized_attributes ||= Location.configuration.normalized_fields ensure_valid_normalized_attributes! @normalized_attributes end |
#normalized_attributes=(attributes) ⇒ Object
45 46 47 48 |
# File 'app/models/location/address_form.rb', line 45 def normalized_attributes=(attributes) @normalized_attributes = Array(attributes) ensure_valid_normalized_attributes! end |
#presence ⇒ Object
36 37 38 |
# File 'app/models/location/address_form.rb', line 36 def presence @presence || validate_presence_of(AddressForm.default_presence_attributes) end |
#validate_presence_of(attributes) ⇒ Object
66 67 68 69 70 71 72 |
# File 'app/models/location/address_form.rb', line 66 def validate_presence_of(attributes) attributes = Array(attributes) @presence = self.attributes.keys.inject({}) do |hash, attr| hash[attr] = attributes.include?(attr) hash end end |