active_hash 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MTE0YzI0ZDYzNTQ0OTVmOTI1Zjk4MmZlZWZlNGNlNGVmZjEyMzAxMg==
5
- data.tar.gz: !binary |-
6
- YTQwOGViNjkwZWJlOTkzZWZiZDgxNGU0NDgwZDVkNzE4OWY2MTE5Nw==
7
- SHA512:
8
- metadata.gz: !binary |-
9
- Y2U2MGUzZjdkZDg3ODYyM2Q1NDNmODgyNTY0YjM0N2U2ZTYyOGIzZmFlYWMz
10
- MTBmNjBjMTVjZDFhMzU4M2Q5ODcxMmI4NzYxMGNlNWNiNTg2MjZhNGQ1MmZk
11
- MmRhYTI0OWIzMzliNWFkN2E3ZjRmMDhmNmViNzg1ZTNlYjZjYjE=
12
- data.tar.gz: !binary |-
13
- MTU4NzNmZjdiNzM1MzkyYjA4MTMxOTJjZjhkMzJhNTQ4MTMzYTQ5NGFkOWI1
14
- YjRmYzRlZmRhMWRmYzQ1OWY0ZjY1ZWY4NGUyZDZmMjEwNGIwMzNjZjMzZTJl
15
- NjhjMzZlNTFkOTA2MDU4YjQwZTMwN2U0ODhjNTY3NWM2ZWIwZmM=
1
+ ---
2
+ SHA512:
3
+ data.tar.gz: 9d8d6b6e4fa0369a177c9b9b67ef4e143ebb3bd4e427adf5e77dc0e8447d794fa3f5a40598dc1daa0452f52cb636745933b0b07a3239a947066032ff009d848f
4
+ metadata.gz: 0f191d2cae8465f16f94f91d6c063274d4f381b1ea354549e48555fc0811467eadc61714d12970bd9b330c795b90d9a2dec428f9fe963addd4121d243e412aa6
5
+ SHA1:
6
+ data.tar.gz: 854bde47211e64f3ff0654dafb5758ac53ab324b
7
+ metadata.gz: 602de7a522546a375e46d7d75a576ffcfd1ab076
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ 2013-10-24 (v1.2.1)
2
+ - fixed nasty bug in belongs_to that would prevent users from passing procs (thanks for the issue freebird0221)
3
+ - fixed bug where passing in a separate class name to belongs_to_active_hash would raise an exception (mauriciopasquier)
4
+
1
5
  2013-10-01 (v1.2.0)
2
6
  - belongs_to is back!
3
7
  - added support for primary key options for belongs_to (tomtaylor)
data/README.md CHANGED
@@ -54,7 +54,7 @@ You can also use _create_:
54
54
  create :id => 2, :name => "Canada"
55
55
  end
56
56
 
57
- If you are Pat Nakajima, you probably prefer _add_:
57
+ You can also use _add_:
58
58
 
59
59
  class Country < ActiveHash::Base
60
60
  field :name
@@ -192,13 +192,26 @@ In versions of ActiveRecord previous to 3.1, you should be able to do the follow
192
192
  belongs_to :country
193
193
  end
194
194
 
195
- However, as of ActiveRecord 3.1 support for ActiveRecord's `belong_to` is broken. Instead, you must use the `belongs_to_active_hash` method:
195
+ However, as of ActiveRecord 3.1 support for ActiveRecord's `belong_to` is broken. Instead, you must extend ActiveHash::Associations::ActiveRecordExtensions method:
196
196
 
197
197
  class Country < ActiveHash::Base
198
198
  end
199
199
 
200
200
  class Person < ActiveRecord::Base
201
201
  extend ActiveHash::Associations::ActiveRecordExtensions
202
+ belongs_to :country
203
+ end
204
+
205
+ NOTE: this needs to be called on a subclass of ActiveRecord::Base. If you extend ActiveRecord::Base, it will not work.
206
+ If you want to extend ActiveRecord::Base so all your AR models can belong to ActiveHash::Base objects, you can use the
207
+ `belongs_to_active_hash` method:
208
+
209
+ ActiveRecord::Base.extend ActiveHash::Associations::ActiveRecordExtensions
210
+
211
+ class Country < ActiveHash::Base
212
+ end
213
+
214
+ class Person < ActiveRecord::Base
202
215
  belongs_to_active_hash :country
203
216
  end
204
217
 
@@ -1,5 +1,5 @@
1
1
  module ActiveHash
2
2
  module Gem
3
- VERSION = "1.2.0"
3
+ VERSION = "1.2.1"
4
4
  end
5
5
  end
@@ -3,7 +3,10 @@ module ActiveHash
3
3
 
4
4
  module ActiveRecordExtensions
5
5
 
6
- def belongs_to(name, options = {})
6
+ def belongs_to(*args)
7
+ our_args = args.dup
8
+ options = our_args.extract_options!
9
+ name = our_args.shift
7
10
  options = {:class_name => name.to_s.camelize }.merge(options)
8
11
  klass = options[:class_name].constantize
9
12
  if klass < ActiveHash::Base
@@ -17,9 +20,10 @@ module ActiveHash
17
20
  options = {
18
21
  :class_name => association_id.to_s.camelize,
19
22
  :foreign_key => association_id.to_s.foreign_key,
20
- :primary_key => association_id.to_s.camelize.constantize.primary_key,
21
23
  :shortcuts => []
22
24
  }.merge(options)
25
+ # Define default primary_key with provided class_name if any
26
+ options[:primary_key] ||= options[:class_name].constantize.primary_key
23
27
  options[:shortcuts] = [options[:shortcuts]] unless options[:shortcuts].kind_of?(Array)
24
28
 
25
29
  define_method(association_id) do
@@ -178,6 +178,21 @@ describe ActiveHash::Base, "associations" do
178
178
  describe ActiveHash::Associations::ActiveRecordExtensions do
179
179
 
180
180
  describe "#belongs_to" do
181
+
182
+ if ActiveRecord::VERSION::MAJOR > 3
183
+ it "doesn't interfere with AR's procs in belongs_to methods" do
184
+ School.belongs_to :country, lambda{ where( ) }
185
+ school = School.new
186
+ country = Country.create!
187
+ school.country = country
188
+ school.country.should == country
189
+ school.country_id.should == country.id
190
+ school.save!
191
+ school.reload
192
+ school.reload.country_id.should == country.id
193
+ end
194
+ end
195
+
181
196
  it "sets up an ActiveRecord association for non-ActiveHash objects" do
182
197
  School.belongs_to :country
183
198
  school = School.new
@@ -260,6 +275,13 @@ describe ActiveHash::Base, "associations" do
260
275
  association.should_not be_nil
261
276
  association.klass.name.should == SchoolStatus.name
262
277
  end
278
+
279
+ it "handles custom association names" do
280
+ School.belongs_to_active_hash :status, :class_name => 'SchoolStatus'
281
+ association = School.reflect_on_association(:status)
282
+ association.should_not be_nil
283
+ association.klass.name.should == SchoolStatus.name
284
+ end
263
285
  end
264
286
  end
265
287
 
metadata CHANGED
@@ -1,9 +1,9 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: active_hash
3
- version: !ruby/object:Gem::Version
4
- version: 1.2.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.1
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - Jeff Dean
8
8
  - Mike Dalessio
9
9
  - Corey Innis
@@ -27,86 +27,74 @@ authors:
27
27
  autorequire:
28
28
  bindir: bin
29
29
  cert_chain: []
30
- date: 2012-01-18 00:00:00.000000000 Z
31
- dependencies:
32
- - !ruby/object:Gem::Dependency
33
- name: activesupport
34
- requirement: !ruby/object:Gem::Requirement
35
- requirements:
36
- - - ! '>='
37
- - !ruby/object:Gem::Version
38
- version: 2.2.2
30
+
31
+ date: 2012-01-18 00:00:00 Z
32
+ dependencies:
33
+ - !ruby/object:Gem::Dependency
39
34
  type: :runtime
40
- prerelease: false
41
- version_requirements: !ruby/object:Gem::Requirement
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
35
+ version_requirements: &id001 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
45
39
  version: 2.2.2
46
- - !ruby/object:Gem::Dependency
47
- name: rspec
48
- requirement: !ruby/object:Gem::Requirement
49
- requirements:
50
- - - ~>
51
- - !ruby/object:Gem::Version
52
- version: 2.2.0
53
- type: :development
40
+ - - <
41
+ - !ruby/object:Gem::Version
42
+ version: "4"
43
+ name: activesupport
54
44
  prerelease: false
55
- version_requirements: !ruby/object:Gem::Requirement
56
- requirements:
45
+ requirement: *id001
46
+ - !ruby/object:Gem::Dependency
47
+ type: :development
48
+ version_requirements: &id002 !ruby/object:Gem::Requirement
49
+ requirements:
57
50
  - - ~>
58
- - !ruby/object:Gem::Version
51
+ - !ruby/object:Gem::Version
59
52
  version: 2.2.0
60
- - !ruby/object:Gem::Dependency
61
- name: sqlite3
62
- requirement: !ruby/object:Gem::Requirement
63
- requirements:
64
- - - ! '>='
65
- - !ruby/object:Gem::Version
66
- version: '0'
67
- type: :development
53
+ name: rspec
68
54
  prerelease: false
69
- version_requirements: !ruby/object:Gem::Requirement
70
- requirements:
71
- - - ! '>='
72
- - !ruby/object:Gem::Version
73
- version: '0'
74
- - !ruby/object:Gem::Dependency
75
- name: activerecord
76
- requirement: !ruby/object:Gem::Requirement
77
- requirements:
78
- - - ! '>='
79
- - !ruby/object:Gem::Version
80
- version: 2.2.2
55
+ requirement: *id002
56
+ - !ruby/object:Gem::Dependency
81
57
  type: :development
58
+ version_requirements: &id003 !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - &id005
61
+ - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ name: sqlite3
82
65
  prerelease: false
83
- version_requirements: !ruby/object:Gem::Requirement
84
- requirements:
85
- - - ! '>='
86
- - !ruby/object:Gem::Version
66
+ requirement: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ type: :development
69
+ version_requirements: &id004 !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
87
73
  version: 2.2.2
88
- - !ruby/object:Gem::Dependency
89
- name: appraisal
90
- requirement: !ruby/object:Gem::Requirement
91
- requirements:
92
- - - ! '>='
93
- - !ruby/object:Gem::Version
94
- version: '0'
74
+ - - <
75
+ - !ruby/object:Gem::Version
76
+ version: "4"
77
+ name: activerecord
78
+ prerelease: false
79
+ requirement: *id004
80
+ - !ruby/object:Gem::Dependency
95
81
  type: :development
82
+ version_requirements: &id006 !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - *id005
85
+ name: appraisal
96
86
  prerelease: false
97
- version_requirements: !ruby/object:Gem::Requirement
98
- requirements:
99
- - - ! '>='
100
- - !ruby/object:Gem::Version
101
- version: '0'
87
+ requirement: *id006
102
88
  description:
103
89
  email: jeff@zilkey.com
104
90
  executables: []
91
+
105
92
  extensions: []
106
- extra_rdoc_files:
93
+
94
+ extra_rdoc_files:
107
95
  - LICENSE
108
96
  - README.md
109
- files:
97
+ files:
110
98
  - CHANGELOG
111
99
  - LICENSE
112
100
  - README.md
@@ -131,28 +119,28 @@ files:
131
119
  - spec/spec_helper.rb
132
120
  homepage: http://github.com/zilkey/active_hash
133
121
  licenses: []
122
+
134
123
  metadata: {}
124
+
135
125
  post_install_message:
136
126
  rdoc_options: []
137
- require_paths:
127
+
128
+ require_paths:
138
129
  - lib
139
- required_ruby_version: !ruby/object:Gem::Requirement
140
- requirements:
141
- - - ! '>='
142
- - !ruby/object:Gem::Version
143
- version: '0'
144
- required_rubygems_version: !ruby/object:Gem::Requirement
145
- requirements:
146
- - - ! '>='
147
- - !ruby/object:Gem::Version
148
- version: '0'
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - *id005
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - *id005
149
136
  requirements: []
137
+
150
138
  rubyforge_project:
151
- rubygems_version: 2.1.5
139
+ rubygems_version: 2.0.10
152
140
  signing_key:
153
141
  specification_version: 3
154
142
  summary: An ActiveRecord-like model that uses a hash or file as a datasource
155
- test_files:
143
+ test_files:
156
144
  - Gemfile
157
145
  - spec/active_file/base_spec.rb
158
146
  - spec/active_hash/base_spec.rb