active_hash 0.8.2 → 0.8.3
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 +4 -0
- data/Gemfile +2 -3
- data/Gemfile.lock +30 -0
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/active_hash.gemspec +8 -5
- data/lib/active_hash/base.rb +16 -13
- data/lib/enum/enum.rb +2 -1
- data/spec/active_hash/base_spec.rb +10 -3
- data/spec/associations/associations_spec.rb +16 -5
- data/spec/enum/enum_spec.rb +6 -6
- data/spec/spec_helper.rb +0 -4
- metadata +16 -5
data/CHANGELOG
CHANGED
data/Gemfile
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
source :gemcutter
|
2
2
|
|
3
|
-
gem "activerecord", "
|
4
|
-
gem "activesupport", "
|
3
|
+
gem "activerecord", "2.3.8", :require => "active_record"
|
4
|
+
gem "activesupport", "2.3.8"
|
5
5
|
gem "rspec", ">= 1.3.0"
|
6
6
|
gem "fixjour", "0.4.1"
|
7
|
-
gem "acts_as_fu", "0.0.5"
|
8
7
|
gem "jeweler", "1.4.0"
|
9
8
|
gem "sqlite3-ruby", ">= 1.2.5"
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activerecord (2.3.8)
|
5
|
+
activesupport (= 2.3.8)
|
6
|
+
activesupport (2.3.8)
|
7
|
+
fixjour (0.4.1)
|
8
|
+
activerecord
|
9
|
+
gemcutter (0.6.1)
|
10
|
+
git (1.2.5)
|
11
|
+
jeweler (1.4.0)
|
12
|
+
gemcutter (>= 0.1.0)
|
13
|
+
git (>= 1.2.5)
|
14
|
+
rubyforge (>= 2.0.0)
|
15
|
+
json_pure (1.4.6)
|
16
|
+
rspec (1.3.0)
|
17
|
+
rubyforge (2.0.4)
|
18
|
+
json_pure (>= 1.1.7)
|
19
|
+
sqlite3-ruby (1.3.1)
|
20
|
+
|
21
|
+
PLATFORMS
|
22
|
+
ruby
|
23
|
+
|
24
|
+
DEPENDENCIES
|
25
|
+
activerecord (= 2.3.8)
|
26
|
+
activesupport (= 2.3.8)
|
27
|
+
fixjour (= 0.4.1)
|
28
|
+
jeweler (= 1.4.0)
|
29
|
+
rspec (>= 1.3.0)
|
30
|
+
sqlite3-ruby (>= 1.2.5)
|
data/Rakefile
CHANGED
@@ -10,7 +10,7 @@ begin
|
|
10
10
|
gem.homepage = "http://github.com/zilkey/active_hash"
|
11
11
|
gem.authors = ["Jeff Dean", "Mike Dalessio", "Corey Innis", "Peter Jaros", "Brandon Keene", "Brian Takita", "Pat Nakajima", "John Pignata", "Michael Schubert", "Jeremy Weiskotten"]
|
12
12
|
gem.add_dependency('activesupport', [">= 2.2.2"])
|
13
|
-
gem.post_install_message = ""
|
13
|
+
gem.post_install_message = "NOTE: Enums have changed to use underscores.\n\nYou may have to do a search and replace to get your suite green."
|
14
14
|
end
|
15
15
|
Jeweler::GemcutterTasks.new
|
16
16
|
rescue LoadError
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.8.
|
1
|
+
0.8.3
|
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.
|
8
|
+
s.version = "0.8.3"
|
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", "Michael Schubert", "Jeremy Weiskotten"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-09-17}
|
13
13
|
s.email = %q{jeff@zilkey.com}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE",
|
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
".gitignore",
|
21
21
|
"CHANGELOG",
|
22
22
|
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
23
24
|
"LICENSE",
|
24
25
|
"README.md",
|
25
26
|
"Rakefile",
|
@@ -44,10 +45,12 @@ Gem::Specification.new do |s|
|
|
44
45
|
"spec/spec_helper.rb"
|
45
46
|
]
|
46
47
|
s.homepage = %q{http://github.com/zilkey/active_hash}
|
47
|
-
s.post_install_message = %q{
|
48
|
+
s.post_install_message = %q{NOTE: Enums have changed to use underscores.
|
49
|
+
|
50
|
+
You may have to do a search and replace to get your suite green.}
|
48
51
|
s.rdoc_options = ["--charset=UTF-8"]
|
49
52
|
s.require_paths = ["lib"]
|
50
|
-
s.rubygems_version = %q{1.3.
|
53
|
+
s.rubygems_version = %q{1.3.7}
|
51
54
|
s.summary = %q{An ActiveRecord-like model that uses a hash or file as a datasource}
|
52
55
|
s.test_files = [
|
53
56
|
"spec/active_file/base_spec.rb",
|
@@ -62,7 +65,7 @@ Gem::Specification.new do |s|
|
|
62
65
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
63
66
|
s.specification_version = 3
|
64
67
|
|
65
|
-
if Gem::Version.new(Gem::
|
68
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
66
69
|
s.add_runtime_dependency(%q<activesupport>, [">= 2.2.2"])
|
67
70
|
else
|
68
71
|
s.add_dependency(%q<activesupport>, [">= 2.2.2"])
|
data/lib/active_hash/base.rb
CHANGED
@@ -9,7 +9,9 @@ module ActiveHash
|
|
9
9
|
attr_reader :field_names
|
10
10
|
|
11
11
|
def the_meta_class
|
12
|
-
|
12
|
+
class << self
|
13
|
+
self
|
14
|
+
end
|
13
15
|
end
|
14
16
|
|
15
17
|
def data=(array_of_hashes)
|
@@ -17,7 +19,7 @@ module ActiveHash
|
|
17
19
|
@records = nil
|
18
20
|
write_inheritable_attribute(:data, array_of_hashes)
|
19
21
|
if array_of_hashes
|
20
|
-
auto_assign_fields(
|
22
|
+
auto_assign_fields(array_of_hashes)
|
21
23
|
array_of_hashes.each do |hash|
|
22
24
|
insert new(hash)
|
23
25
|
end
|
@@ -32,7 +34,7 @@ module ActiveHash
|
|
32
34
|
end
|
33
35
|
|
34
36
|
def next_id
|
35
|
-
max_record = all.max {|a, b| a.id <=> b.id }
|
37
|
+
max_record = all.max { |a, b| a.id <=> b.id }
|
36
38
|
if max_record.nil?
|
37
39
|
1
|
38
40
|
elsif max_record.id.is_a?(Numeric)
|
@@ -46,6 +48,7 @@ module ActiveHash
|
|
46
48
|
mark_dirty
|
47
49
|
record
|
48
50
|
end
|
51
|
+
|
49
52
|
alias_method :add, :create
|
50
53
|
|
51
54
|
def create!(attributes = {})
|
@@ -73,28 +76,28 @@ module ActiveHash
|
|
73
76
|
@records = []
|
74
77
|
end
|
75
78
|
|
76
|
-
def find(id, *args)
|
79
|
+
def find(id, * args)
|
77
80
|
case id
|
78
81
|
when nil
|
79
82
|
nil
|
80
83
|
when :all
|
81
84
|
all
|
82
85
|
when Array
|
83
|
-
all.select {|record| id.map(
|
86
|
+
all.select { |record| id.map(& :to_i).include?(record.id) }
|
84
87
|
else
|
85
88
|
find_by_id(id) || begin
|
86
|
-
|
87
|
-
|
89
|
+
raise RecordNotFound.new("Couldn't find #{name} with ID=#{id}")
|
90
|
+
end
|
88
91
|
end
|
89
92
|
end
|
90
93
|
|
91
94
|
def find_by_id(id)
|
92
|
-
all.detect {|record| record.id == id.to_i}
|
95
|
+
all.detect { |record| record.id == id.to_i }
|
93
96
|
end
|
94
97
|
|
95
98
|
delegate :first, :last, :to => :all
|
96
99
|
|
97
|
-
def fields(*args)
|
100
|
+
def fields(* args)
|
98
101
|
options = args.extract_options!
|
99
102
|
args.each do |field|
|
100
103
|
field(field, options)
|
@@ -122,7 +125,7 @@ module ActiveHash
|
|
122
125
|
end
|
123
126
|
end
|
124
127
|
|
125
|
-
def method_missing(method_name, *args)
|
128
|
+
def method_missing(method_name, * args)
|
126
129
|
return super unless respond_to? method_name
|
127
130
|
|
128
131
|
config = configuration_for_custom_finder(method_name)
|
@@ -179,7 +182,7 @@ module ActiveHash
|
|
179
182
|
unless singleton_methods.include?(method_name)
|
180
183
|
the_meta_class.instance_eval do
|
181
184
|
define_method(method_name) do |name|
|
182
|
-
all.detect {|record| record.send(field_name) == name }
|
185
|
+
all.detect { |record| record.send(field_name) == name }
|
183
186
|
end
|
184
187
|
end
|
185
188
|
end
|
@@ -193,7 +196,7 @@ module ActiveHash
|
|
193
196
|
the_meta_class.instance_eval do
|
194
197
|
unless singleton_methods.include?(method_name)
|
195
198
|
define_method(method_name) do |name|
|
196
|
-
all.select {|record| record.send(field_name) == name }
|
199
|
+
all.select { |record| record.send(field_name) == name }
|
197
200
|
end
|
198
201
|
end
|
199
202
|
end
|
@@ -273,7 +276,7 @@ module ActiveHash
|
|
273
276
|
alias quoted_id id
|
274
277
|
|
275
278
|
def new_record?
|
276
|
-
!
|
279
|
+
!self.class.all.include?(self)
|
277
280
|
end
|
278
281
|
|
279
282
|
def destroyed?
|
data/lib/enum/enum.rb
CHANGED
@@ -590,14 +590,21 @@ describe ActiveHash, "Base" do
|
|
590
590
|
{:id => 1, :name => "foo"}
|
591
591
|
]
|
592
592
|
|
593
|
-
|
594
|
-
|
595
|
-
|
593
|
+
class Book < ActiveRecord::Base
|
594
|
+
establish_connection :adapter => "sqlite3", :database => ":memory:"
|
595
|
+
connection.create_table(:books, :force => true) do |t|
|
596
|
+
t.text :subject_type
|
597
|
+
t.integer :subject_id
|
598
|
+
end
|
596
599
|
belongs_to :subject, :polymorphic => true
|
597
600
|
belongs_to :country
|
598
601
|
end
|
599
602
|
end
|
600
603
|
|
604
|
+
after do
|
605
|
+
Object.send :remove_const, :Book
|
606
|
+
end
|
607
|
+
|
601
608
|
it "should be possible to use it as a parent" do
|
602
609
|
book = Book.new
|
603
610
|
book.country = Country.first
|
@@ -3,11 +3,16 @@ require 'spec/spec_helper'
|
|
3
3
|
describe ActiveHash::Base, "associations" do
|
4
4
|
|
5
5
|
before do
|
6
|
-
|
6
|
+
class Country < ActiveRecord::Base
|
7
|
+
establish_connection :adapter => "sqlite3", :database => ":memory:"
|
8
|
+
connection.create_table(:countries, :force => true) {}
|
7
9
|
end
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
+
class School < ActiveRecord::Base
|
12
|
+
establish_connection :adapter => "sqlite3", :database => ":memory:"
|
13
|
+
connection.create_table(:schools, :force => true) do |t|
|
14
|
+
t.integer :city_id
|
15
|
+
end
|
11
16
|
end
|
12
17
|
|
13
18
|
class City < ActiveHash::Base
|
@@ -18,14 +23,20 @@ describe ActiveHash::Base, "associations" do
|
|
18
23
|
include ActiveHash::Associations
|
19
24
|
end
|
20
25
|
|
21
|
-
|
22
|
-
|
26
|
+
class Book < ActiveRecord::Base
|
27
|
+
establish_connection :adapter => "sqlite3", :database => ":memory:"
|
28
|
+
connection.create_table(:books, :force => true) do |t|
|
29
|
+
t.integer :author_id
|
30
|
+
end
|
23
31
|
end
|
24
32
|
end
|
25
33
|
|
26
34
|
after do
|
27
35
|
Object.send :remove_const, :City
|
28
36
|
Object.send :remove_const, :Author
|
37
|
+
Object.send :remove_const, :Country
|
38
|
+
Object.send :remove_const, :School
|
39
|
+
Object.send :remove_const, :Book
|
29
40
|
end
|
30
41
|
|
31
42
|
describe "#has_many" do
|
data/spec/enum/enum_spec.rb
CHANGED
@@ -45,10 +45,10 @@ describe ActiveHash::Base, "enum" do
|
|
45
45
|
]
|
46
46
|
enum_accessor :name
|
47
47
|
end
|
48
|
-
|
49
|
-
Movie::
|
50
|
-
Movie::
|
51
|
-
Movie::
|
48
|
+
|
49
|
+
Movie::DIE_HARD.name.should == 'Die Hard 2'
|
50
|
+
Movie::THE_INFORMANT.name.should == 'The Informant!'
|
51
|
+
Movie::IN_OUT.name.should == 'In & Out'
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
@@ -77,9 +77,9 @@ describe ActiveHash::Base, "enum" do
|
|
77
77
|
|
78
78
|
describe ".delete_all" do
|
79
79
|
it "unsets all constants for deleted records" do
|
80
|
-
Borough.const_defined?("
|
80
|
+
Borough.const_defined?("STATEN_ISLAND").should be_true
|
81
81
|
Borough.delete_all.should be_true
|
82
|
-
Borough.const_defined?("
|
82
|
+
Borough.const_defined?("STATEN_ISLAND").should be_false
|
83
83
|
end
|
84
84
|
end
|
85
85
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,6 @@
|
|
1
1
|
require 'spec'
|
2
2
|
require 'spec/autorun'
|
3
3
|
require 'active_record'
|
4
|
-
silence_stream STDERR do
|
5
|
-
require 'acts_as_fu' # suppress activerecord warnings
|
6
|
-
end
|
7
4
|
require 'fixjour'
|
8
5
|
|
9
6
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
@@ -19,6 +16,5 @@ ActiveHash::Base.class_eval do
|
|
19
16
|
end
|
20
17
|
|
21
18
|
Spec::Runner.configure do |config|
|
22
|
-
config.include ActsAsFu
|
23
19
|
config.include Fixjour
|
24
20
|
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_hash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 57
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 8
|
8
|
-
-
|
9
|
-
version: 0.8.
|
9
|
+
- 3
|
10
|
+
version: 0.8.3
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Jeff Dean
|
@@ -23,16 +24,18 @@ autorequire:
|
|
23
24
|
bindir: bin
|
24
25
|
cert_chain: []
|
25
26
|
|
26
|
-
date: 2010-
|
27
|
+
date: 2010-09-17 00:00:00 -04:00
|
27
28
|
default_executable:
|
28
29
|
dependencies:
|
29
30
|
- !ruby/object:Gem::Dependency
|
30
31
|
name: activesupport
|
31
32
|
prerelease: false
|
32
33
|
requirement: &id001 !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
33
35
|
requirements:
|
34
36
|
- - ">="
|
35
37
|
- !ruby/object:Gem::Version
|
38
|
+
hash: 3
|
36
39
|
segments:
|
37
40
|
- 2
|
38
41
|
- 2
|
@@ -54,6 +57,7 @@ files:
|
|
54
57
|
- .gitignore
|
55
58
|
- CHANGELOG
|
56
59
|
- Gemfile
|
60
|
+
- Gemfile.lock
|
57
61
|
- LICENSE
|
58
62
|
- README.md
|
59
63
|
- Rakefile
|
@@ -80,29 +84,36 @@ has_rdoc: true
|
|
80
84
|
homepage: http://github.com/zilkey/active_hash
|
81
85
|
licenses: []
|
82
86
|
|
83
|
-
post_install_message:
|
87
|
+
post_install_message: |-
|
88
|
+
NOTE: Enums have changed to use underscores.
|
89
|
+
|
90
|
+
You may have to do a search and replace to get your suite green.
|
84
91
|
rdoc_options:
|
85
92
|
- --charset=UTF-8
|
86
93
|
require_paths:
|
87
94
|
- lib
|
88
95
|
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
89
97
|
requirements:
|
90
98
|
- - ">="
|
91
99
|
- !ruby/object:Gem::Version
|
100
|
+
hash: 3
|
92
101
|
segments:
|
93
102
|
- 0
|
94
103
|
version: "0"
|
95
104
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
96
106
|
requirements:
|
97
107
|
- - ">="
|
98
108
|
- !ruby/object:Gem::Version
|
109
|
+
hash: 3
|
99
110
|
segments:
|
100
111
|
- 0
|
101
112
|
version: "0"
|
102
113
|
requirements: []
|
103
114
|
|
104
115
|
rubyforge_project:
|
105
|
-
rubygems_version: 1.3.
|
116
|
+
rubygems_version: 1.3.7
|
106
117
|
signing_key:
|
107
118
|
specification_version: 3
|
108
119
|
summary: An ActiveRecord-like model that uses a hash or file as a datasource
|