phony_rails 0.0.12 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +5 -3
- data/README.md +1 -1
- data/lib/phony_rails.rb +10 -6
- data/lib/phony_rails/version.rb +1 -1
- metadata +2 -2
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -24,7 +24,7 @@ Or install it yourself as:
|
|
24
24
|
In your model add:
|
25
25
|
|
26
26
|
class SomeModel < ActiveRecord::Base
|
27
|
-
phony_normalize :phone_number, :default_country_code => 'US' # Normalizes the attribute itself
|
27
|
+
phony_normalize :phone_number, :default_country_code => 'US' # Normalizes the attribute itself on validation
|
28
28
|
phony_normalized_method :fax_number # Creates method normalized_fax_number that returns the normalized version of fax_number
|
29
29
|
end
|
30
30
|
|
data/lib/phony_rails.rb
CHANGED
@@ -16,7 +16,10 @@ module PhonyRails
|
|
16
16
|
'IT' => '39',
|
17
17
|
'US' => '1',
|
18
18
|
'AU' => '61',
|
19
|
-
'LU' => '352'
|
19
|
+
'LU' => '352',
|
20
|
+
'AT' => '43',
|
21
|
+
'CH' => '41',
|
22
|
+
'PL' => '48'
|
20
23
|
}
|
21
24
|
|
22
25
|
# This method requires a country_code attribute (eg. NL) and phone_number to be set.
|
@@ -86,13 +89,14 @@ module PhonyRails
|
|
86
89
|
# phony_normalized_method :fax_number, :default_country_code => 'US'
|
87
90
|
# Creates a normalized_fax_number method.
|
88
91
|
def phony_normalized_method(*attributes)
|
89
|
-
|
90
|
-
|
92
|
+
main_options = attributes.last.is_a?(Hash) ? attributes.pop : {}
|
93
|
+
main_options.assert_valid_keys :country_code, :default_country_code
|
91
94
|
attributes.each do |attribute|
|
92
|
-
|
93
|
-
|
95
|
+
raise StandardError, "Instance method normalized_#{attribute} already exists on #{self.name} (PhonyRails)" if self.instance_methods.include?(:"normalized_#{attribute}")
|
96
|
+
define_method :"normalized_#{attribute}" do |options = {}|
|
97
|
+
raise ArgumentError, "No attribute/method #{attribute} found on #{self.class.name} (PhonyRails)" if not self.respond_to?(attribute)
|
94
98
|
options[:country_code] ||= self.country_code if self.respond_to?(:country_code)
|
95
|
-
PhonyRails.normalize_number(self
|
99
|
+
PhonyRails.normalize_number(self.send(attribute), main_options.merge(options))
|
96
100
|
end
|
97
101
|
end
|
98
102
|
end
|
data/lib/phony_rails/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phony_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: phony
|