active_hash 1.2.3 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CHANGELOG +6 -0
- data/README.md +75 -14
- data/active_hash.gemspec +9 -64
- data/lib/active_file/base.rb +6 -1
- data/lib/active_file/hash_and_array_files.rb +24 -0
- data/lib/active_file/multiple_files.rb +33 -0
- data/lib/active_hash.rb +3 -0
- data/lib/active_hash/base.rb +19 -5
- data/lib/active_hash/version.rb +1 -1
- data/lib/active_json/base.rb +25 -0
- data/lib/active_yaml/base.rb +5 -5
- data/lib/associations/associations.rb +3 -3
- metadata +15 -99
- data/Gemfile +0 -3
- data/lib/util/ruby_engine.rb +0 -68
- data/lib/util/ruby_version.rb +0 -139
- data/spec/active_file/base_spec.rb +0 -131
- data/spec/active_hash/base_spec.rb +0 -1051
- data/spec/active_yaml/base_spec.rb +0 -119
- data/spec/associations/associations_spec.rb +0 -427
- data/spec/enum/enum_spec.rb +0 -101
- data/spec/lint_spec.rb +0 -36
- data/spec/spec_helper.rb +0 -8
data/lib/active_yaml/base.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module ActiveYaml
|
2
2
|
|
3
3
|
class Base < ActiveFile::Base
|
4
|
+
extend ActiveFile::HashAndArrayFiles
|
4
5
|
class << self
|
5
6
|
def load_file
|
6
7
|
if (data = raw_data).is_a?(Array)
|
@@ -10,15 +11,14 @@ module ActiveYaml
|
|
10
11
|
end
|
11
12
|
end
|
12
13
|
|
13
|
-
def raw_data
|
14
|
-
YAML.load_file(full_path)
|
15
|
-
end
|
16
|
-
|
17
14
|
def extension
|
18
15
|
"yml"
|
19
16
|
end
|
20
17
|
|
18
|
+
private
|
19
|
+
def load_path(path)
|
20
|
+
YAML.load_file(path)
|
21
|
+
end
|
21
22
|
end
|
22
23
|
end
|
23
|
-
|
24
24
|
end
|
@@ -8,8 +8,8 @@ module ActiveHash
|
|
8
8
|
options = our_args.extract_options!
|
9
9
|
name = our_args.shift
|
10
10
|
options = {:class_name => name.to_s.camelize }.merge(options)
|
11
|
-
klass = options[:class_name].constantize
|
12
|
-
if klass < ActiveHash::Base
|
11
|
+
klass = options[:class_name].constantize rescue nil
|
12
|
+
if klass && klass < ActiveHash::Base
|
13
13
|
belongs_to_active_hash(name, options)
|
14
14
|
else
|
15
15
|
super
|
@@ -82,7 +82,7 @@ module ActiveHash
|
|
82
82
|
klass = options[:class_name].constantize
|
83
83
|
primary_key_value = send(options[:primary_key])
|
84
84
|
|
85
|
-
if ActiveRecord.const_defined?(:Relation) && klass < ActiveRecord::Relation
|
85
|
+
if Object.const_defined?(:ActiveRecord) && ActiveRecord.const_defined?(:Relation) && klass < ActiveRecord::Relation
|
86
86
|
klass.where(options[:foreign_key] => primary_key_value)
|
87
87
|
elsif klass.respond_to?(:scoped)
|
88
88
|
klass.scoped(:conditions => {options[:foreign_key] => primary_key_value})
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_hash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Dean
|
@@ -24,10 +24,11 @@ authors:
|
|
24
24
|
- Desmond Bowe
|
25
25
|
- Matthew O'Riordan
|
26
26
|
- Brett Richardson
|
27
|
+
- Rachel Heaton
|
27
28
|
autorequire:
|
28
29
|
bindir: bin
|
29
30
|
cert_chain: []
|
30
|
-
date:
|
31
|
+
date: 2014-02-19 00:00:00.000000000 Z
|
31
32
|
dependencies:
|
32
33
|
- !ruby/object:Gem::Dependency
|
33
34
|
name: activesupport
|
@@ -43,108 +44,31 @@ dependencies:
|
|
43
44
|
- - ! '>='
|
44
45
|
- !ruby/object:Gem::Version
|
45
46
|
version: 2.2.2
|
46
|
-
|
47
|
-
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
-
requirements:
|
50
|
-
- - ~>
|
51
|
-
- !ruby/object:Gem::Version
|
52
|
-
version: 2.2.0
|
53
|
-
type: :development
|
54
|
-
prerelease: false
|
55
|
-
version_requirements: !ruby/object:Gem::Requirement
|
56
|
-
requirements:
|
57
|
-
- - ~>
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
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
|
68
|
-
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
|
81
|
-
type: :development
|
82
|
-
prerelease: false
|
83
|
-
version_requirements: !ruby/object:Gem::Requirement
|
84
|
-
requirements:
|
85
|
-
- - ! '>='
|
86
|
-
- !ruby/object:Gem::Version
|
87
|
-
version: 2.2.2
|
88
|
-
- !ruby/object:Gem::Dependency
|
89
|
-
name: wwtd
|
90
|
-
requirement: !ruby/object:Gem::Requirement
|
91
|
-
requirements:
|
92
|
-
- - ! '>='
|
93
|
-
- !ruby/object:Gem::Version
|
94
|
-
version: '0'
|
95
|
-
type: :development
|
96
|
-
prerelease: false
|
97
|
-
version_requirements: !ruby/object:Gem::Requirement
|
98
|
-
requirements:
|
99
|
-
- - ! '>='
|
100
|
-
- !ruby/object:Gem::Version
|
101
|
-
version: '0'
|
102
|
-
- !ruby/object:Gem::Dependency
|
103
|
-
name: rake
|
104
|
-
requirement: !ruby/object:Gem::Requirement
|
105
|
-
requirements:
|
106
|
-
- - ! '>='
|
107
|
-
- !ruby/object:Gem::Version
|
108
|
-
version: '0'
|
109
|
-
type: :development
|
110
|
-
prerelease: false
|
111
|
-
version_requirements: !ruby/object:Gem::Requirement
|
112
|
-
requirements:
|
113
|
-
- - ! '>='
|
114
|
-
- !ruby/object:Gem::Version
|
115
|
-
version: '0'
|
116
|
-
description:
|
47
|
+
description: Includes the ability to specify data using hashes, yml files or JSON
|
48
|
+
files
|
117
49
|
email: jeff@zilkey.com
|
118
50
|
executables: []
|
119
51
|
extensions: []
|
120
|
-
extra_rdoc_files:
|
121
|
-
- LICENSE
|
122
|
-
- README.md
|
52
|
+
extra_rdoc_files: []
|
123
53
|
files:
|
124
54
|
- CHANGELOG
|
125
55
|
- LICENSE
|
126
56
|
- README.md
|
127
57
|
- active_hash.gemspec
|
128
58
|
- lib/active_file/base.rb
|
59
|
+
- lib/active_file/hash_and_array_files.rb
|
60
|
+
- lib/active_file/multiple_files.rb
|
61
|
+
- lib/active_hash.rb
|
129
62
|
- lib/active_hash/base.rb
|
130
63
|
- lib/active_hash/version.rb
|
131
|
-
- lib/
|
64
|
+
- lib/active_json/base.rb
|
132
65
|
- lib/active_yaml/aliases.rb
|
133
66
|
- lib/active_yaml/base.rb
|
134
67
|
- lib/associations/associations.rb
|
135
68
|
- lib/enum/enum.rb
|
136
|
-
- lib/util/ruby_engine.rb
|
137
|
-
- lib/util/ruby_version.rb
|
138
|
-
- Gemfile
|
139
|
-
- spec/active_file/base_spec.rb
|
140
|
-
- spec/active_hash/base_spec.rb
|
141
|
-
- spec/active_yaml/base_spec.rb
|
142
|
-
- spec/associations/associations_spec.rb
|
143
|
-
- spec/enum/enum_spec.rb
|
144
|
-
- spec/lint_spec.rb
|
145
|
-
- spec/spec_helper.rb
|
146
69
|
homepage: http://github.com/zilkey/active_hash
|
147
|
-
licenses:
|
70
|
+
licenses:
|
71
|
+
- MIT
|
148
72
|
metadata: {}
|
149
73
|
post_install_message:
|
150
74
|
rdoc_options: []
|
@@ -162,16 +86,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
162
86
|
version: '0'
|
163
87
|
requirements: []
|
164
88
|
rubyforge_project:
|
165
|
-
rubygems_version: 2.1
|
89
|
+
rubygems_version: 2.2.1
|
166
90
|
signing_key:
|
167
|
-
specification_version:
|
91
|
+
specification_version: 4
|
168
92
|
summary: An ActiveRecord-like model that uses a hash or file as a datasource
|
169
|
-
test_files:
|
170
|
-
- Gemfile
|
171
|
-
- spec/active_file/base_spec.rb
|
172
|
-
- spec/active_hash/base_spec.rb
|
173
|
-
- spec/active_yaml/base_spec.rb
|
174
|
-
- spec/associations/associations_spec.rb
|
175
|
-
- spec/enum/enum_spec.rb
|
176
|
-
- spec/lint_spec.rb
|
177
|
-
- spec/spec_helper.rb
|
93
|
+
test_files: []
|
data/Gemfile
DELETED
data/lib/util/ruby_engine.rb
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
# Sourced from http://rbjl.net/35-how-to-properly-check-for-your-ruby-interpreter-version-and-os
|
2
|
-
# Extracted from http://rubyzucker.info/
|
3
|
-
# Copyright (c) 2010-2013 Jan Lelis <http://happycode.org> released under the MIT license
|
4
|
-
|
5
|
-
class RubyEngine
|
6
|
-
class << self
|
7
|
-
def interpreter
|
8
|
-
case
|
9
|
-
when RUBY_PLATFORM == 'parrot'
|
10
|
-
'cardinal'
|
11
|
-
when Object.constants.include?( :RUBY_ENGINE ) ||
|
12
|
-
Object.constants.include?( 'RUBY_ENGINE' )
|
13
|
-
if RUBY_ENGINE == 'ruby'
|
14
|
-
if RUBY_DESCRIPTION =~ /Enterprise/
|
15
|
-
'ree'
|
16
|
-
else
|
17
|
-
'mri'
|
18
|
-
end
|
19
|
-
else
|
20
|
-
RUBY_ENGINE.to_s # jruby, rbx, ironruby, macruby, etc.
|
21
|
-
end
|
22
|
-
else # probably 1.8
|
23
|
-
'mri'
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def is?(what)
|
28
|
-
what === interpreter
|
29
|
-
end
|
30
|
-
alias is is?
|
31
|
-
|
32
|
-
def to_s
|
33
|
-
interpreter
|
34
|
-
end
|
35
|
-
|
36
|
-
def mri?
|
37
|
-
RubyEngine.is? 'mri'
|
38
|
-
end
|
39
|
-
alias official_ruby? mri?
|
40
|
-
alias ruby? mri?
|
41
|
-
|
42
|
-
def jruby?
|
43
|
-
RubyEngine.is? 'jruby'
|
44
|
-
end
|
45
|
-
alias java? jruby?
|
46
|
-
|
47
|
-
def rubinius?
|
48
|
-
RubyEngine.is? 'rbx'
|
49
|
-
end
|
50
|
-
alias rbx? rubinius?
|
51
|
-
|
52
|
-
def ree?
|
53
|
-
RubyEngine.is? 'ree'
|
54
|
-
end
|
55
|
-
alias enterprise? ree?
|
56
|
-
|
57
|
-
def ironruby?
|
58
|
-
RubyEngine.is? 'ironruby'
|
59
|
-
end
|
60
|
-
alias iron_ruby? ironruby?
|
61
|
-
|
62
|
-
def cardinal?
|
63
|
-
RubyEngine.is? 'cardinal'
|
64
|
-
end
|
65
|
-
alias parrot? cardinal?
|
66
|
-
alias perl? cardinal?
|
67
|
-
end
|
68
|
-
end
|
data/lib/util/ruby_version.rb
DELETED
@@ -1,139 +0,0 @@
|
|
1
|
-
# Sourced from http://rbjl.net/35-how-to-properly-check-for-your-ruby-interpreter-version-and-os
|
2
|
-
# Extracted from http://rubyzucker.info/
|
3
|
-
# Copyright (c) 2010-2013 Jan Lelis <http://happycode.org> released under the MIT license
|
4
|
-
|
5
|
-
### usage examples
|
6
|
-
# RubyVersion
|
7
|
-
### check for the main version with a Float
|
8
|
-
# RubyVersion.is? 1.8
|
9
|
-
### use strings for exacter checking
|
10
|
-
# RubyVersion.is.above '1.8.7'
|
11
|
-
# RubyVersion.is.at_least '1.8.7' # or below, at_most, not
|
12
|
-
### you can use the common comparison operators
|
13
|
-
# RubyVersion >= '1.8.7'
|
14
|
-
# RubyVersion.is.between? '1.8.6', '1.8.7'
|
15
|
-
### relase date checks
|
16
|
-
# RubyVersion.is.older_than Date.today
|
17
|
-
# RubyVersion.is.newer_than '2009-08-19'
|
18
|
-
### accessors
|
19
|
-
# RubyVersion.major # e.g. => 1
|
20
|
-
# RubyVersion.minor # e.g. => 8
|
21
|
-
# RubyVersion.tiny # e.g. => 7
|
22
|
-
# RubyVersion.patchlevel # e.g. => 249
|
23
|
-
# RubyVersion.description # e.g. => "ruby 1.8.7 (2010-01-10 patchlevel 249) [i486-linux]"
|
24
|
-
|
25
|
-
require 'date'
|
26
|
-
require 'time'
|
27
|
-
|
28
|
-
module RubyVersion
|
29
|
-
class << self
|
30
|
-
def to_s
|
31
|
-
RUBY_VERSION
|
32
|
-
end
|
33
|
-
|
34
|
-
# comparable
|
35
|
-
def <=>(other)
|
36
|
-
value = case other
|
37
|
-
when Integer
|
38
|
-
RUBY_VERSION.to_i
|
39
|
-
when Float
|
40
|
-
RUBY_VERSION.to_f
|
41
|
-
when String
|
42
|
-
RUBY_VERSION
|
43
|
-
when Date,Time
|
44
|
-
other.class.parse(RUBY_RELEASE_DATE)
|
45
|
-
else
|
46
|
-
other = other.to_s
|
47
|
-
RUBY_VERSION
|
48
|
-
end
|
49
|
-
value <=> other
|
50
|
-
end
|
51
|
-
include Comparable
|
52
|
-
|
53
|
-
# chaining for dsl-like language
|
54
|
-
def is?(other = nil)
|
55
|
-
if other
|
56
|
-
RubyVersion == other
|
57
|
-
else
|
58
|
-
RubyVersion
|
59
|
-
end
|
60
|
-
end
|
61
|
-
alias is is?
|
62
|
-
|
63
|
-
# aliases
|
64
|
-
alias below <
|
65
|
-
alias below? <
|
66
|
-
alias at_most <=
|
67
|
-
alias at_most? <=
|
68
|
-
alias above >
|
69
|
-
alias above? >
|
70
|
-
alias at_least >=
|
71
|
-
alias at_least? >=
|
72
|
-
alias exactly ==
|
73
|
-
alias exactly? ==
|
74
|
-
def not(other)
|
75
|
-
self != other
|
76
|
-
end
|
77
|
-
alias not? not
|
78
|
-
alias between between?
|
79
|
-
|
80
|
-
# compare dates
|
81
|
-
def newer_than(other)
|
82
|
-
if other.is_a? Date or other.is_a? Time
|
83
|
-
RubyVersion > other
|
84
|
-
else
|
85
|
-
RUBY_RELEASE_DATE > other.to_s
|
86
|
-
end
|
87
|
-
end
|
88
|
-
alias newer_than? newer_than
|
89
|
-
|
90
|
-
def older_than(other)
|
91
|
-
if other.is_a? Date or other.is_a? Time
|
92
|
-
RubyVersion < other
|
93
|
-
else
|
94
|
-
RUBY_RELEASE_DATE < other.to_s
|
95
|
-
end
|
96
|
-
end
|
97
|
-
alias older_than? older_than
|
98
|
-
|
99
|
-
def released_today
|
100
|
-
RubyVersion.date == Date.today
|
101
|
-
end
|
102
|
-
alias released_today? released_today
|
103
|
-
|
104
|
-
# accessors
|
105
|
-
|
106
|
-
def major
|
107
|
-
RUBY_VERSION.to_i
|
108
|
-
end
|
109
|
-
alias main major
|
110
|
-
|
111
|
-
def minor
|
112
|
-
RUBY_VERSION.split('.')[1].to_i
|
113
|
-
end
|
114
|
-
alias mini minor
|
115
|
-
|
116
|
-
def tiny
|
117
|
-
RUBY_VERSION.split('.')[2].to_i
|
118
|
-
end
|
119
|
-
|
120
|
-
alias teeny tiny
|
121
|
-
|
122
|
-
def patchlevel
|
123
|
-
RUBY_PATCHLEVEL
|
124
|
-
end
|
125
|
-
|
126
|
-
def platform
|
127
|
-
RUBY_PLATFORM
|
128
|
-
end
|
129
|
-
|
130
|
-
def release_date
|
131
|
-
Date.parse RUBY_RELEASE_DATE
|
132
|
-
end
|
133
|
-
alias date release_date
|
134
|
-
|
135
|
-
def description
|
136
|
-
RUBY_DESCRIPTION
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
@@ -1,131 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ActiveFile::Base do
|
4
|
-
before do
|
5
|
-
class Country < ActiveFile::Base
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
after do
|
10
|
-
Object.send :remove_const, :Country
|
11
|
-
end
|
12
|
-
|
13
|
-
describe ".filename=" do
|
14
|
-
before do
|
15
|
-
Country.filename = "foo-izzle"
|
16
|
-
|
17
|
-
class Bar < ActiveFile::Base
|
18
|
-
self.filename = "bar-izzle"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
it "sets the filename on a per-subclass basis" do
|
23
|
-
Country.filename.should == "foo-izzle"
|
24
|
-
Bar.filename.should == "bar-izzle"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe ".set_filename" do
|
29
|
-
before do
|
30
|
-
Country.set_filename "foo-izzle"
|
31
|
-
|
32
|
-
class Bar < ActiveFile::Base
|
33
|
-
set_filename "bar-izzle"
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
it "sets the filename on a per-subclass basis" do
|
38
|
-
Country.filename.should == "foo-izzle"
|
39
|
-
Bar.filename.should == "bar-izzle"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe ".root_path=" do
|
44
|
-
before do
|
45
|
-
Country.root_path = "foo-izzle"
|
46
|
-
|
47
|
-
class Bar < ActiveFile::Base
|
48
|
-
self.root_path = "bar-izzle"
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
it "sets the root_path on a per-subclass basis" do
|
53
|
-
Country.root_path.should == "foo-izzle"
|
54
|
-
Bar.root_path.should == "bar-izzle"
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe ".set_root_path" do
|
59
|
-
before do
|
60
|
-
Country.set_root_path "foo-izzle"
|
61
|
-
|
62
|
-
class Bar < ActiveFile::Base
|
63
|
-
set_root_path "bar-izzle"
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
it "sets the root_path on a per-subclass basis" do
|
68
|
-
Country.root_path.should == "foo-izzle"
|
69
|
-
Bar.root_path.should == "bar-izzle"
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
describe ".full_path" do
|
74
|
-
it "defaults to the directory of the calling file" do
|
75
|
-
class Country
|
76
|
-
def self.extension() "foo" end
|
77
|
-
end
|
78
|
-
|
79
|
-
Country.full_path.should == "#{Dir.pwd}/countries.foo"
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
describe ".reload" do
|
84
|
-
before do
|
85
|
-
class Country
|
86
|
-
def self.load_file()
|
87
|
-
{"new_york"=>{"name"=>"New York", "id"=>1}}.values
|
88
|
-
end
|
89
|
-
end
|
90
|
-
Country.reload # initial load
|
91
|
-
end
|
92
|
-
|
93
|
-
context "when nothing has been modified" do
|
94
|
-
it "does not reload anything" do
|
95
|
-
class Country
|
96
|
-
def self.load_file()
|
97
|
-
raise "should not have been called"
|
98
|
-
end
|
99
|
-
end
|
100
|
-
Country.dirty.should be_false
|
101
|
-
Country.reload
|
102
|
-
Country.dirty.should be_false
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
context "when forced" do
|
107
|
-
it "reloads the data" do
|
108
|
-
class Country
|
109
|
-
def self.load_file()
|
110
|
-
{"new_york"=>{"name"=>"New York", "id"=>2}}.values
|
111
|
-
end
|
112
|
-
end
|
113
|
-
Country.dirty.should be_false
|
114
|
-
Country.find_by_id(2).should be_nil
|
115
|
-
Country.reload(true)
|
116
|
-
Country.dirty.should be_false
|
117
|
-
Country.find(2).name.should == "New York"
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
context "when the data has been modified" do
|
122
|
-
it "reloads the data" do
|
123
|
-
Country.create!
|
124
|
-
Country.dirty.should be_true
|
125
|
-
Country.reload
|
126
|
-
Country.dirty.should be_false
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
end
|