active_hash 0.7.6 → 0.7.7
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/CHANGELOG +1 -0
- data/README.md +4 -4
- data/Rakefile +3 -9
- data/VERSION +1 -1
- data/active_hash.gemspec +1 -1
- data/lib/associations/associations.rb +8 -2
- data/spec/associations/associations_spec.rb +32 -2
- metadata +1 -1
data/CHANGELOG
CHANGED
data/README.md
CHANGED
@@ -182,15 +182,15 @@ You can also use standard rails view helpers, like #collection_select:
|
|
182
182
|
|
183
183
|
<%= collection_select :person, :country_id, Country.all, :id, :name %>
|
184
184
|
|
185
|
-
If you
|
185
|
+
If you extend the ActiveHash::Associations module, you can also create associations from your ActiveHash classes, like so:
|
186
186
|
|
187
187
|
class Country < ActiveHash::Base
|
188
|
-
|
188
|
+
extend ActiveHash::Associations
|
189
189
|
has_many :people
|
190
190
|
end
|
191
191
|
|
192
192
|
class Person < ActiveHash::Base
|
193
|
-
|
193
|
+
extend ActiveHash::Associations
|
194
194
|
belongs_to :country
|
195
195
|
has_many :pets
|
196
196
|
end
|
@@ -201,7 +201,7 @@ If you include the ActiveHash::Associations module, you can also create associat
|
|
201
201
|
Once you define a belongs to, you also get the setter method:
|
202
202
|
|
203
203
|
class City < ActiveHash::Base
|
204
|
-
|
204
|
+
extend ActiveHash::Associations
|
205
205
|
belongs_to :state
|
206
206
|
end
|
207
207
|
|
data/Rakefile
CHANGED
@@ -11,7 +11,7 @@ begin
|
|
11
11
|
gem.authors = ["Jeff Dean", "Mike Dalessio", "Corey Innis", "Peter Jaros", "Brandon Keene", "Brian Takita", "Pat Nakajima", "John Pignata"]
|
12
12
|
gem.add_dependency('activesupport', [">= 2.2.2"])
|
13
13
|
end
|
14
|
-
|
14
|
+
Jeweler::GemcutterTasks.new
|
15
15
|
rescue LoadError
|
16
16
|
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
17
17
|
end
|
@@ -33,16 +33,10 @@ task :default => :spec
|
|
33
33
|
|
34
34
|
require 'rake/rdoctask'
|
35
35
|
Rake::RDocTask.new do |rdoc|
|
36
|
-
|
37
|
-
config = YAML.load(File.read('VERSION.yml'))
|
38
|
-
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
39
|
-
else
|
40
|
-
version = ""
|
41
|
-
end
|
36
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
42
37
|
|
43
38
|
rdoc.rdoc_dir = 'rdoc'
|
44
|
-
rdoc.title = "
|
39
|
+
rdoc.title = "the-perfect-gem #{version}"
|
45
40
|
rdoc.rdoc_files.include('README*')
|
46
41
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
47
42
|
end
|
48
|
-
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.7.
|
1
|
+
0.7.7
|
data/active_hash.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{active_hash}
|
8
|
-
s.version = "0.7.
|
8
|
+
s.version = "0.7.7"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jeff Dean", "Mike Dalessio", "Corey Innis", "Peter Jaros", "Brandon Keene", "Brian Takita", "Pat Nakajima", "John Pignata"]
|
@@ -2,10 +2,15 @@ module ActiveHash
|
|
2
2
|
module Associations
|
3
3
|
|
4
4
|
def self.included(base)
|
5
|
-
|
5
|
+
puts %Q{DEPRECATION WARNING: include #{self} should be extend #{self} and will be removed in later versions. Called from #{caller.first}}
|
6
|
+
base.extend self
|
6
7
|
end
|
7
8
|
|
8
|
-
|
9
|
+
def self.extended(base)
|
10
|
+
base.send :extend, Methods
|
11
|
+
end
|
12
|
+
|
13
|
+
module Methods
|
9
14
|
def has_many(association_id, options = {})
|
10
15
|
|
11
16
|
define_method(association_id) do
|
@@ -36,5 +41,6 @@ module ActiveHash
|
|
36
41
|
|
37
42
|
end
|
38
43
|
end
|
44
|
+
|
39
45
|
end
|
40
46
|
end
|
@@ -1,5 +1,35 @@
|
|
1
1
|
require 'spec/spec_helper'
|
2
2
|
|
3
|
+
describe ActiveHash::Base, "associations when included" do
|
4
|
+
before do
|
5
|
+
class City < ActiveHash::Base
|
6
|
+
silence_stream STDOUT do
|
7
|
+
include ActiveHash::Associations
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class Author < ActiveHash::Base
|
12
|
+
silence_stream STDOUT do
|
13
|
+
include ActiveHash::Associations
|
14
|
+
end
|
15
|
+
field :publisher_id
|
16
|
+
field :city_id
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
after do
|
21
|
+
Object.send :remove_const, :City
|
22
|
+
Object.send :remove_const, :Author
|
23
|
+
end
|
24
|
+
|
25
|
+
it "works until the deprecation period is up" do
|
26
|
+
Author.belongs_to :city
|
27
|
+
city = City.create!
|
28
|
+
author = Author.new :city => city
|
29
|
+
author.city.should == city
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
3
33
|
describe ActiveHash::Base, "associations" do
|
4
34
|
|
5
35
|
before do
|
@@ -8,11 +38,11 @@ describe ActiveHash::Base, "associations" do
|
|
8
38
|
|
9
39
|
class City < ActiveHash::Base
|
10
40
|
field :country_id
|
11
|
-
|
41
|
+
extend ActiveHash::Associations
|
12
42
|
end
|
13
43
|
|
14
44
|
class Author < ActiveHash::Base
|
15
|
-
|
45
|
+
extend ActiveHash::Associations
|
16
46
|
field :publisher_id
|
17
47
|
field :city_id
|
18
48
|
end
|