belongs_to_city 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -73,6 +73,12 @@ bc. script/generate belongs_to_city --include-seed --jq-autocomplete
73
73
 
74
74
  h2. Use the City structure in your models
75
75
 
76
+ h3. Important
77
+
78
+ p. For the time being, if youd like to use other association methods including the city in your models. It is required that you include the following line of code
79
+
80
+ bc. belongs_to :city, :class_name => 'City'
81
+
76
82
  p. To use the city structure in your models, *include an integer city_id* column in the model you want to use it and paste the following code into the model.
77
83
 
78
84
  bc. belongs_to_city
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.0
1
+ 0.7.1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{belongs_to_city}
8
- s.version = "0.7.0"
8
+ s.version = "0.7.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Adrian Cuadros"]
12
- s.date = %q{2010-05-21}
12
+ s.date = %q{2010-05-24}
13
13
  s.description = %q{Creates the basic structure to enable City structure integration with any model and eases autocomplete search}
14
14
  s.email = %q{adrian@innku.com}
15
15
  s.extra_rdoc_files = [
@@ -12,12 +12,12 @@ module BelongsToCity
12
12
  city_collector = city_attribute.to_s.pluralize.to_sym
13
13
 
14
14
  attr_accessor city_collector
15
- belongs_to city_attribute, :class_name => "City"
16
15
 
17
16
  #Getter and Setter Methods
18
17
  define_method "#{city_attribute}_name" do
18
+ city = send(city_attribute)
19
19
  return read_attribute("#{city_attribute}_name") if read_attribute("#{city_attribute}_name")
20
- return "#{send(city_attribute).name}, #{send(city_attribute).state.short2}" if read_attribute(city_attribute)
20
+ return "#{city.name}, #{city.state.short2}" if city
21
21
  end
22
22
 
23
23
  define_method "#{city_attribute}_name=" do |city_name|
@@ -40,8 +40,11 @@ module BelongsToCity
40
40
  no_cities_message ||= "We couldn't find any city in your request"
41
41
  validate do |record|
42
42
  cities = record.read_attribute(city_collector)
43
- record.errors.add(city_attribute_helper, too_many_cities_message) if cities.size > 1 rescue nil
44
- record.errors.add(city_attribute_helper, no_cities_message) if (cities.nil? or cities.size == 0)
43
+ city = record.read_attribute(city_attribute)
44
+ if cities
45
+ record.errors.add(city_attribute_helper, too_many_cities_message) if (cities.size > 1 rescue nil)
46
+ record.errors.add(city_attribute_helper, no_cities_message) if (cities.nil? or cities.size == 0)
47
+ end
45
48
  end
46
49
  end
47
50
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 7
8
- - 0
9
- version: 0.7.0
8
+ - 1
9
+ version: 0.7.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Adrian Cuadros
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-21 00:00:00 -05:00
17
+ date: 2010-05-24 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency