phony_rails 0.0.12 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
- source 'https://rubygems.org'
1
+ source :rubygems
2
+ gemspec # Specify your gem's dependencies in phony_number.gemspec
2
3
 
3
- # Specify your gem's dependencies in phony_number.gemspec
4
- gemspec
4
+ # For testing
5
+ gem 'rspec'
6
+ gem 'sqlite3'
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
 
@@ -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
- options = attributes.last.is_a?(Hash) ? attributes.pop : {}
90
- options.assert_valid_keys :country_code, :default_country_code
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
- define_method :"normalized_#{attribute}" do
93
- raise ArgumentError, "Attribute #{attribute} was not found on #{self.name} (PhonyRails)" unless self.class.attribute_method?(attribute)
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[attribute], options)
99
+ PhonyRails.normalize_number(self.send(attribute), main_options.merge(options))
96
100
  end
97
101
  end
98
102
  end
@@ -1,3 +1,3 @@
1
1
  module PhonyRails
2
- VERSION = "0.0.12"
2
+ VERSION = "0.1.0"
3
3
  end
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.12
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-06 00:00:00.000000000 Z
12
+ date: 2012-06-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: phony