ambry 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog.md +7 -0
- data/README.md +8 -0
- data/extras/bench.rb +0 -2
- data/lib/ambry/active_model.rb +2 -2
- data/lib/ambry/hash_proxy.rb +13 -2
- data/lib/ambry/model.rb +5 -4
- data/lib/ambry/version.rb +1 -1
- data/spec/model_spec.rb +6 -0
- metadata +15 -15
data/Changelog.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# Ambry Changelog
|
2
2
|
|
3
|
+
## [0.2.1](https://github.com/norman/ambry/tree/0.2.1) - 2001-09-20 ([diff](https://github.com/norman/ambry/compare/0.2.0...0.2.1))
|
4
|
+
|
5
|
+
### [Norman Clarke](https://github.com/norman)
|
6
|
+
|
7
|
+
* Fix handling of attributes with falsy values
|
8
|
+
|
9
|
+
|
3
10
|
## [0.2.0](https://github.com/norman/ambry/tree/0.2.0) - 2001-09-05 ([diff](https://github.com/norman/ambry/compare/0.1.2...0.2.0))
|
4
11
|
|
5
12
|
### [Norman Clarke](https://github.com/norman)
|
data/README.md
CHANGED
@@ -59,6 +59,14 @@ quick samples.
|
|
59
59
|
first_alphabetical = Country.alphabetical.first
|
60
60
|
last_alphabetical = Country.alphabetical.last
|
61
61
|
|
62
|
+
## When should I use Ambry?
|
63
|
+
|
64
|
+
Ambry can be useful for refactoring code with large hash constants and long case
|
65
|
+
statements. Sometimes it's hard to figure out where code ends and data begins,
|
66
|
+
but if your code looks like it could be simplified significantly by putting some
|
67
|
+
things in a data store, yet it's not enough data to justify something like
|
68
|
+
SQLite, then Ambry could be a good fit.
|
69
|
+
|
62
70
|
|
63
71
|
## Installation
|
64
72
|
|
data/extras/bench.rb
CHANGED
data/lib/ambry/active_model.rb
CHANGED
data/lib/ambry/hash_proxy.rb
CHANGED
@@ -6,14 +6,25 @@ module Ambry
|
|
6
6
|
class HashProxy
|
7
7
|
attr :hash
|
8
8
|
|
9
|
+
def self.with(hash, &block)
|
10
|
+
new.with(hash, &block)
|
11
|
+
end
|
12
|
+
|
9
13
|
# Allows accessing a hash attribute as a method.
|
10
14
|
def method_missing(symbol)
|
11
15
|
hash[symbol] or hash[symbol.to_s] or raise NoMethodError
|
12
16
|
end
|
13
17
|
|
14
18
|
# Allows accessing a hash attribute as hash key, either a string or symbol.
|
15
|
-
def [](
|
16
|
-
hash
|
19
|
+
def [](key)
|
20
|
+
if hash.key?(key) then hash[key]
|
21
|
+
elsif hash.key?(key.to_sym) then hash[key.to_sym]
|
22
|
+
elsif hash.key?(key.to_s) then hash[key.to_s]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def key?(key)
|
27
|
+
hash.key?(key) or hash.key?(key.to_sym) or hash.key?(key.to_s)
|
17
28
|
end
|
18
29
|
|
19
30
|
# Remove the hash.
|
data/lib/ambry/model.rb
CHANGED
@@ -27,7 +27,7 @@ module Ambry
|
|
27
27
|
attribute_names << name.to_sym
|
28
28
|
class_eval(<<-EOM, __FILE__, __LINE__ + 1)
|
29
29
|
def #{name}
|
30
|
-
@#{name}
|
30
|
+
defined?(@#{name}) ? @#{name} : @attributes[:#{name}]
|
31
31
|
end
|
32
32
|
|
33
33
|
def #{name}=(value)
|
@@ -152,9 +152,10 @@ module Ambry
|
|
152
152
|
|
153
153
|
# Update this instance's attributes and invoke #save.
|
154
154
|
def update(attributes)
|
155
|
-
|
156
|
-
|
157
|
-
|
155
|
+
HashProxy.with(attributes) do |proxy|
|
156
|
+
self.class.attribute_names.each do |name|
|
157
|
+
send("#{name}=", proxy[name]) if proxy.key?(name)
|
158
|
+
end
|
158
159
|
end
|
159
160
|
save
|
160
161
|
end
|
data/lib/ambry/version.rb
CHANGED
data/spec/model_spec.rb
CHANGED
@@ -150,6 +150,12 @@ describe Ambry::Model do
|
|
150
150
|
assert_equal count, Person.count
|
151
151
|
end
|
152
152
|
|
153
|
+
it "should allow false as an update value (regression)" do
|
154
|
+
p = Person.get("moe@3stooges.com")
|
155
|
+
p.update(:name => false)
|
156
|
+
assert_equal false, p.name
|
157
|
+
end
|
158
|
+
|
153
159
|
end
|
154
160
|
|
155
161
|
describe "#save" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ambry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-09-
|
12
|
+
date: 2011-09-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ffaker
|
16
|
-
requirement: &
|
16
|
+
requirement: &70104361299880 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70104361299880
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: minitest
|
27
|
-
requirement: &
|
27
|
+
requirement: &70104361299380 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 2.2.2
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70104361299380
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: mocha
|
38
|
-
requirement: &
|
38
|
+
requirement: &70104361298940 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70104361298940
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: activesupport
|
49
|
-
requirement: &
|
49
|
+
requirement: &70104361298360 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '3.0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70104361298360
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: activemodel
|
60
|
-
requirement: &
|
60
|
+
requirement: &70104361297820 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '3.0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70104361297820
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rake
|
71
|
-
requirement: &
|
71
|
+
requirement: &70104361297440 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70104361297440
|
80
80
|
description: ! " Ambry is not an ORM, man! It's a database and ORM replacement
|
81
81
|
for (mostly)\n static models and small datasets. It provides ActiveModel compatibility,
|
82
82
|
and\n flexible searching and storage.\n"
|
@@ -137,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
137
|
version: '0'
|
138
138
|
requirements: []
|
139
139
|
rubyforge_project: ! '[none]'
|
140
|
-
rubygems_version: 1.8.
|
140
|
+
rubygems_version: 1.8.5
|
141
141
|
signing_key:
|
142
142
|
specification_version: 3
|
143
143
|
summary: An ActiveModel-compatible ORM-like library for storing model instances in
|