active_hash 0.7.9 → 0.8.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/.gitignore +1 -0
- data/CHANGELOG +4 -0
- data/Gemfile +8 -0
- data/README.md +14 -0
- data/Rakefile +2 -14
- data/VERSION +1 -1
- data/active_hash.gemspec +6 -18
- data/lib/active_hash/base.rb +6 -3
- data/spec/active_hash/base_spec.rb +23 -1
- data/spec/associations/associations_spec.rb +19 -0
- data/spec/spec_helper.rb +1 -1
- metadata +23 -24
- data/geminstaller.yml +0 -13
data/.gitignore
CHANGED
data/CHANGELOG
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
2010-04-25
|
2
|
+
- When ActiveRecord model belongs_to an ActiveHash and the associated id is nil, returns nil instead of raising RecordNotFound (Jeremy Weiskotten)
|
3
|
+
- Merged Nakajima's "add" alias for "create" - gotta save those ASCII characters :)
|
4
|
+
|
1
5
|
2010-03-01
|
2
6
|
- Removed "extend"-related deprecations - they didn't play well with rails class loading
|
3
7
|
|
data/Gemfile
ADDED
data/README.md
CHANGED
@@ -40,6 +40,20 @@ A quick example would be:
|
|
40
40
|
country.name # => "Mexico"
|
41
41
|
country.name? # => true
|
42
42
|
|
43
|
+
You can also use _create_:
|
44
|
+
|
45
|
+
class Country < ActiveHash::Base
|
46
|
+
create :id => 1, :name => "US"
|
47
|
+
create :id => 2, :name => "Canada"
|
48
|
+
end
|
49
|
+
|
50
|
+
If you are Pat Nakajima, you probably prefer _add_:
|
51
|
+
|
52
|
+
class Country < ActiveHash::Base
|
53
|
+
add :id => 1, :name => "US"
|
54
|
+
add :id => 2, :name => "Canada"
|
55
|
+
end
|
56
|
+
|
43
57
|
## Auto-Defined fields
|
44
58
|
|
45
59
|
ActiveHash will auto-define all fields for you when you load the hash. For example, if you have the following class:
|
data/Rakefile
CHANGED
@@ -8,21 +8,9 @@ begin
|
|
8
8
|
gem.summary = %Q{An ActiveRecord-like model that uses a hash or file as a datasource}
|
9
9
|
gem.email = "jeff@zilkey.com"
|
10
10
|
gem.homepage = "http://github.com/zilkey/active_hash"
|
11
|
-
gem.authors = ["Jeff Dean", "Mike Dalessio", "Corey Innis", "Peter Jaros", "Brandon Keene", "Brian Takita", "Pat Nakajima", "John Pignata"]
|
11
|
+
gem.authors = ["Jeff Dean", "Mike Dalessio", "Corey Innis", "Peter Jaros", "Brandon Keene", "Brian Takita", "Pat Nakajima", "John Pignata", "Jeremy Weiskotten"]
|
12
12
|
gem.add_dependency('activesupport', [">= 2.2.2"])
|
13
|
-
gem.post_install_message =
|
14
|
-
|
15
|
-
extend ActiveHash::Associations
|
16
|
-
extend ActiveHash::Enum
|
17
|
-
|
18
|
-
becomes
|
19
|
-
|
20
|
-
include ActiveHash::Associations
|
21
|
-
include ActiveHash::Enum
|
22
|
-
|
23
|
-
Sorry for the inconvenience.
|
24
|
-
|
25
|
-
}
|
13
|
+
gem.post_install_message = ""
|
26
14
|
end
|
27
15
|
Jeweler::GemcutterTasks.new
|
28
16
|
rescue LoadError
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.8.0
|
data/active_hash.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{active_hash}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.8.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Jeff Dean", "Mike Dalessio", "Corey Innis", "Peter Jaros", "Brandon Keene", "Brian Takita", "Pat Nakajima", "John Pignata"]
|
12
|
-
s.date = %q{2010-
|
11
|
+
s.authors = ["Jeff Dean", "Mike Dalessio", "Corey Innis", "Peter Jaros", "Brandon Keene", "Brian Takita", "Pat Nakajima", "John Pignata", "Jeremy Weiskotten"]
|
12
|
+
s.date = %q{2010-04-25}
|
13
13
|
s.email = %q{jeff@zilkey.com}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE",
|
@@ -19,12 +19,12 @@ Gem::Specification.new do |s|
|
|
19
19
|
".document",
|
20
20
|
".gitignore",
|
21
21
|
"CHANGELOG",
|
22
|
+
"Gemfile",
|
22
23
|
"LICENSE",
|
23
24
|
"README.md",
|
24
25
|
"Rakefile",
|
25
26
|
"VERSION",
|
26
27
|
"active_hash.gemspec",
|
27
|
-
"geminstaller.yml",
|
28
28
|
"lib/active_file/base.rb",
|
29
29
|
"lib/active_hash.rb",
|
30
30
|
"lib/active_hash/base.rb",
|
@@ -44,22 +44,10 @@ Gem::Specification.new do |s|
|
|
44
44
|
"spec/spec_helper.rb"
|
45
45
|
]
|
46
46
|
s.homepage = %q{http://github.com/zilkey/active_hash}
|
47
|
-
s.post_install_message = %q{
|
48
|
-
|
49
|
-
extend ActiveHash::Associations
|
50
|
-
extend ActiveHash::Enum
|
51
|
-
|
52
|
-
becomes
|
53
|
-
|
54
|
-
include ActiveHash::Associations
|
55
|
-
include ActiveHash::Enum
|
56
|
-
|
57
|
-
Sorry for the inconvenience.
|
58
|
-
|
59
|
-
}
|
47
|
+
s.post_install_message = %q{}
|
60
48
|
s.rdoc_options = ["--charset=UTF-8"]
|
61
49
|
s.require_paths = ["lib"]
|
62
|
-
s.rubygems_version = %q{1.3.
|
50
|
+
s.rubygems_version = %q{1.3.6}
|
63
51
|
s.summary = %q{An ActiveRecord-like model that uses a hash or file as a datasource}
|
64
52
|
s.test_files = [
|
65
53
|
"spec/active_file/base_spec.rb",
|
data/lib/active_hash/base.rb
CHANGED
@@ -39,6 +39,7 @@ module ActiveHash
|
|
39
39
|
record.save
|
40
40
|
record
|
41
41
|
end
|
42
|
+
alias_method :add, :create
|
42
43
|
|
43
44
|
def create!(attributes = {})
|
44
45
|
record = new(attributes)
|
@@ -66,6 +67,8 @@ module ActiveHash
|
|
66
67
|
|
67
68
|
def find(id, *args)
|
68
69
|
case id
|
70
|
+
when nil
|
71
|
+
nil
|
69
72
|
when :all
|
70
73
|
all
|
71
74
|
when Array
|
@@ -211,13 +214,13 @@ module ActiveHash
|
|
211
214
|
def base_class
|
212
215
|
ActiveHash::Base
|
213
216
|
end
|
214
|
-
|
217
|
+
|
215
218
|
def reload
|
216
219
|
self.data = read_inheritable_attribute(:data)
|
217
220
|
end
|
218
|
-
|
221
|
+
|
219
222
|
private :reload
|
220
|
-
|
223
|
+
|
221
224
|
end
|
222
225
|
|
223
226
|
attr_reader :attributes
|
@@ -68,6 +68,28 @@ describe ActiveHash, "Base" do
|
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
+
describe ".add" do
|
72
|
+
before do
|
73
|
+
Country.fields :name
|
74
|
+
end
|
75
|
+
|
76
|
+
it "adds a record" do
|
77
|
+
proc {
|
78
|
+
Country.add :name => "Russia"
|
79
|
+
}.should change { Country.count }
|
80
|
+
end
|
81
|
+
|
82
|
+
it "returns the record" do
|
83
|
+
record = Country.add :name => "Russia"
|
84
|
+
record.name.should == "Russia"
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should populate the id" do
|
88
|
+
record = Country.add :name => "Russia"
|
89
|
+
record.id.should_not be_nil
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
71
93
|
describe ".all" do
|
72
94
|
before do
|
73
95
|
Country.field :name
|
@@ -726,7 +748,7 @@ describe ActiveHash, "Base" do
|
|
726
748
|
|
727
749
|
before do
|
728
750
|
Country.field :name
|
729
|
-
Fixjour do
|
751
|
+
Fixjour :allow_redundancy => true do
|
730
752
|
define_builder(Country) do |klass, overrides|
|
731
753
|
klass.new(:name => 'Pat')
|
732
754
|
end
|
@@ -6,6 +6,10 @@ describe ActiveHash::Base, "associations" do
|
|
6
6
|
build_model :countries do
|
7
7
|
end
|
8
8
|
|
9
|
+
build_model :schools do
|
10
|
+
integer :city_id
|
11
|
+
end
|
12
|
+
|
9
13
|
class City < ActiveHash::Base
|
10
14
|
include ActiveHash::Associations
|
11
15
|
end
|
@@ -65,6 +69,21 @@ describe ActiveHash::Base, "associations" do
|
|
65
69
|
|
66
70
|
describe "#belongs_to" do
|
67
71
|
|
72
|
+
context "with an ActiveRecord child" do
|
73
|
+
it "finds the correct records" do
|
74
|
+
School.belongs_to :city
|
75
|
+
city = City.create
|
76
|
+
school = School.create :city_id => city.id
|
77
|
+
school.city.should == city
|
78
|
+
end
|
79
|
+
|
80
|
+
it "returns nil when the record does not exist" do
|
81
|
+
School.belongs_to :city
|
82
|
+
school = School.create :city_id => nil
|
83
|
+
school.city.should be_nil
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
68
87
|
context "with an ActiveRecord parent" do
|
69
88
|
it "find the correct records" do
|
70
89
|
City.belongs_to :country
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_hash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 8
|
8
|
+
- 0
|
9
|
+
version: 0.8.0
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Jeff Dean
|
@@ -12,23 +17,28 @@ authors:
|
|
12
17
|
- Brian Takita
|
13
18
|
- Pat Nakajima
|
14
19
|
- John Pignata
|
20
|
+
- Jeremy Weiskotten
|
15
21
|
autorequire:
|
16
22
|
bindir: bin
|
17
23
|
cert_chain: []
|
18
24
|
|
19
|
-
date: 2010-
|
25
|
+
date: 2010-04-25 00:00:00 -04:00
|
20
26
|
default_executable:
|
21
27
|
dependencies:
|
22
28
|
- !ruby/object:Gem::Dependency
|
23
29
|
name: activesupport
|
24
|
-
|
25
|
-
|
26
|
-
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
prerelease: false
|
31
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
27
32
|
requirements:
|
28
33
|
- - ">="
|
29
34
|
- !ruby/object:Gem::Version
|
35
|
+
segments:
|
36
|
+
- 2
|
37
|
+
- 2
|
38
|
+
- 2
|
30
39
|
version: 2.2.2
|
31
|
-
|
40
|
+
type: :runtime
|
41
|
+
version_requirements: *id001
|
32
42
|
description:
|
33
43
|
email: jeff@zilkey.com
|
34
44
|
executables: []
|
@@ -42,12 +52,12 @@ files:
|
|
42
52
|
- .document
|
43
53
|
- .gitignore
|
44
54
|
- CHANGELOG
|
55
|
+
- Gemfile
|
45
56
|
- LICENSE
|
46
57
|
- README.md
|
47
58
|
- Rakefile
|
48
59
|
- VERSION
|
49
60
|
- active_hash.gemspec
|
50
|
-
- geminstaller.yml
|
51
61
|
- lib/active_file/base.rb
|
52
62
|
- lib/active_hash.rb
|
53
63
|
- lib/active_hash/base.rb
|
@@ -69,20 +79,7 @@ has_rdoc: true
|
|
69
79
|
homepage: http://github.com/zilkey/active_hash
|
70
80
|
licenses: []
|
71
81
|
|
72
|
-
post_install_message:
|
73
|
-
NOTE: Breaking change! Please change any extend statements to include statements:
|
74
|
-
|
75
|
-
extend ActiveHash::Associations
|
76
|
-
extend ActiveHash::Enum
|
77
|
-
|
78
|
-
becomes
|
79
|
-
|
80
|
-
include ActiveHash::Associations
|
81
|
-
include ActiveHash::Enum
|
82
|
-
|
83
|
-
Sorry for the inconvenience.
|
84
|
-
|
85
|
-
|
82
|
+
post_install_message: ""
|
86
83
|
rdoc_options:
|
87
84
|
- --charset=UTF-8
|
88
85
|
require_paths:
|
@@ -91,18 +88,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
91
88
|
requirements:
|
92
89
|
- - ">="
|
93
90
|
- !ruby/object:Gem::Version
|
91
|
+
segments:
|
92
|
+
- 0
|
94
93
|
version: "0"
|
95
|
-
version:
|
96
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
95
|
requirements:
|
98
96
|
- - ">="
|
99
97
|
- !ruby/object:Gem::Version
|
98
|
+
segments:
|
99
|
+
- 0
|
100
100
|
version: "0"
|
101
|
-
version:
|
102
101
|
requirements: []
|
103
102
|
|
104
103
|
rubyforge_project:
|
105
|
-
rubygems_version: 1.3.
|
104
|
+
rubygems_version: 1.3.6
|
106
105
|
signing_key:
|
107
106
|
specification_version: 3
|
108
107
|
summary: An ActiveRecord-like model that uses a hash or file as a datasource
|
data/geminstaller.yml
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
defaults:
|
2
|
-
install_options: --source=http://gemcutter.org --include-dependencies --no-ri --no-rdoc
|
3
|
-
gems:
|
4
|
-
- name: acts_as_fu
|
5
|
-
version: 0.0.5
|
6
|
-
- name: activesupport
|
7
|
-
version: >= 2.2.2
|
8
|
-
- name: rspec
|
9
|
-
version: >= 1.3.0
|
10
|
-
- name: fixjour
|
11
|
-
version: 0.3.0
|
12
|
-
- name: jeweler
|
13
|
-
version: 1.4.0
|