Class: Location::AddressForm

Inherits:
Object
  • Object
show all
Includes:
Form
Defined in:
app/models/location/address_form.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Form

add_callbacks, base, included, #persisted?, #save

Instance Attribute Details

#modelObject

Returns the value of attribute model.



32
33
34
# File 'app/models/location/address_form.rb', line 32

def model
  @model
end

Class Method Details

.default_presence_attributesObject



9
10
11
# File 'app/models/location/address_form.rb', line 9

def self.default_presence_attributes
  i{postal_code address district city state}
end

.float_attributesObject



17
18
19
# File 'app/models/location/address_form.rb', line 17

def self.float_attributes
  i{latitude longitude}
end

.normalizable_attributesObject



5
6
7
# File 'app/models/location/address_form.rb', line 5

def self.normalizable_attributes
  i{state city district}
end

.string_attributesObject



13
14
15
# File 'app/models/location/address_form.rb', line 13

def self.string_attributes
  i{postal_code address number complement district city state}
end

Instance Method Details

#address_attributesObject



38
39
40
41
# File 'app/models/location/address_form.rb', line 38

def address_attributes
  attributes = %w{postal_code address number complement latitude longitude}
  values_for_attributes(attributes)
end

#attribute_normalized?(attr) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
# File 'app/models/location/address_form.rb', line 60

def attribute_normalized?(attr)
  normalized_attributes.include?(attr)
end

#ensure_valid_normalized_attributes!Object



54
55
56
57
58
# File 'app/models/location/address_form.rb', line 54

def ensure_valid_normalized_attributes!
  unless valid_normalized_attributes?
    raise ::StandardError.new, "Invalid normalizable attributes"
  end
end

#normalized_attributesObject



48
49
50
51
52
# File 'app/models/location/address_form.rb', line 48

def normalized_attributes
  @normalized_attributes ||= Location.configuration.normalized_fields
  ensure_valid_normalized_attributes!
  @normalized_attributes
end

#normalized_attributes=(attributes) ⇒ Object



43
44
45
46
# File 'app/models/location/address_form.rb', line 43

def normalized_attributes=(attributes)
  @normalized_attributes = Array(attributes)
  ensure_valid_normalized_attributes!
end

#presenceObject



34
35
36
# File 'app/models/location/address_form.rb', line 34

def presence
  @presence || validate_presence_of(AddressForm.default_presence_attributes)
end

#validate_presence_of(attributes) ⇒ Object



64
65
66
67
68
69
70
# File 'app/models/location/address_form.rb', line 64

def validate_presence_of(attributes)
  attributes = Array(attributes)
  @presence = self.attributes.keys.inject({}) do |hash, attr|
    hash[attr] = attributes.include?(attr)
    hash
  end
end