characterizable 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/characterizable.gemspec +5 -2
- data/lib/characterizable.rb +11 -0
- data/test/test_characterizable.rb +15 -0
- metadata +22 -6
data/Rakefile
CHANGED
@@ -12,6 +12,7 @@ begin
|
|
12
12
|
gem.authors = ["Andy Rossmeissl", "Seamus Abshere"]
|
13
13
|
gem.add_dependency 'blockenspiel', '>=0.3.2'
|
14
14
|
gem.add_dependency 'activesupport', '>=2.3.5'
|
15
|
+
gem.add_dependency 'to_json_fix', '>=0.0.1'
|
15
16
|
gem.add_development_dependency "shoulda", ">= 0"
|
16
17
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
18
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.11
|
data/characterizable.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{characterizable}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.11"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Andy Rossmeissl", "Seamus Abshere"]
|
12
|
-
s.date = %q{2010-07-
|
12
|
+
s.date = %q{2010-07-16}
|
13
13
|
s.description = %q{Characterize the relationship between "attributes" (getters/setters) of instances of a class}
|
14
14
|
s.email = %q{seamus@abshere.net}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -45,15 +45,18 @@ Gem::Specification.new do |s|
|
|
45
45
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
46
46
|
s.add_runtime_dependency(%q<blockenspiel>, [">= 0.3.2"])
|
47
47
|
s.add_runtime_dependency(%q<activesupport>, [">= 2.3.5"])
|
48
|
+
s.add_runtime_dependency(%q<to_json_fix>, [">= 0.0.1"])
|
48
49
|
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
49
50
|
else
|
50
51
|
s.add_dependency(%q<blockenspiel>, [">= 0.3.2"])
|
51
52
|
s.add_dependency(%q<activesupport>, [">= 2.3.5"])
|
53
|
+
s.add_dependency(%q<to_json_fix>, [">= 0.0.1"])
|
52
54
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
53
55
|
end
|
54
56
|
else
|
55
57
|
s.add_dependency(%q<blockenspiel>, [">= 0.3.2"])
|
56
58
|
s.add_dependency(%q<activesupport>, [">= 2.3.5"])
|
59
|
+
s.add_dependency(%q<to_json_fix>, [">= 0.0.1"])
|
57
60
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
58
61
|
end
|
59
62
|
end
|
data/lib/characterizable.rb
CHANGED
@@ -9,9 +9,11 @@ require 'active_support/version'
|
|
9
9
|
active_support/core_ext/array/wrap
|
10
10
|
active_support/core_ext/module/aliasing
|
11
11
|
active_support/core_ext/module/delegation
|
12
|
+
active_support/json
|
12
13
|
}.each do |active_support_3_requirement|
|
13
14
|
require active_support_3_requirement
|
14
15
|
end if ActiveSupport::VERSION::MAJOR == 3
|
16
|
+
require 'to_json_fix'
|
15
17
|
|
16
18
|
module Characterizable
|
17
19
|
def self.included(klass)
|
@@ -30,6 +32,12 @@ module Characterizable
|
|
30
32
|
class BetterHash < ::Hash
|
31
33
|
# In Ruby 1.9, running select/reject/etc. gives you back a hash
|
32
34
|
if RUBY_VERSION < '1.9'
|
35
|
+
def to_hash
|
36
|
+
Hash.new.replace self
|
37
|
+
end
|
38
|
+
def to_json(*)
|
39
|
+
to_hash.to_json
|
40
|
+
end
|
33
41
|
def reject(&block)
|
34
42
|
inject(Characterizable::BetterHash.new) do |memo, ary|
|
35
43
|
unless block.call(*ary)
|
@@ -157,6 +165,9 @@ module Characterizable
|
|
157
165
|
@options = options
|
158
166
|
Blockenspiel.invoke block, self if block_given?
|
159
167
|
end
|
168
|
+
def to_json(*)
|
169
|
+
{ :name => name, :trumps => trumps, :prerequisite => prerequisite, :options => options }.to_json
|
170
|
+
end
|
160
171
|
def inspect
|
161
172
|
"<Characterizable::Characteristic name=#{name.inspect} trumps=#{trumps.inspect} prerequisite=#{prerequisite.inspect} options=#{options.inspect}>"
|
162
173
|
end
|
@@ -363,4 +363,19 @@ class TestCharacterizable < Test::Unit::TestCase
|
|
363
363
|
assert_equal({}, snapshot.slice(:make))
|
364
364
|
end
|
365
365
|
|
366
|
+
should 'allow a BetterHash to be turned into a normal Hash' do
|
367
|
+
assert_equal Hash, Characterizable::BetterHash.new.to_hash.class
|
368
|
+
end
|
369
|
+
|
370
|
+
should 'be nice to active_support to_json for characteristics (i.e. BetterHashes)' do
|
371
|
+
a = Automobile.new
|
372
|
+
a.make = 'Ford'
|
373
|
+
assert_equal "{\"make\":\"Ford\"}", a.characteristics.to_json
|
374
|
+
end
|
375
|
+
|
376
|
+
should 'be nice to active_support to_json for snapshots' do
|
377
|
+
a = Automobile.new
|
378
|
+
a.make = 'Ford'
|
379
|
+
assert_equal "{\"make\":{\"trumps\":[],\"name\":\"make\",\"options\":{},\"prerequisite\":null}}", a.characteristics.effective.to_json
|
380
|
+
end
|
366
381
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: characterizable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 11
|
10
|
+
version: 0.0.11
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Andy Rossmeissl
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-07-
|
19
|
+
date: 2010-07-16 00:00:00 -05:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -52,9 +52,25 @@ dependencies:
|
|
52
52
|
type: :runtime
|
53
53
|
version_requirements: *id002
|
54
54
|
- !ruby/object:Gem::Dependency
|
55
|
-
name:
|
55
|
+
name: to_json_fix
|
56
56
|
prerelease: false
|
57
57
|
requirement: &id003 !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
hash: 29
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
- 0
|
66
|
+
- 1
|
67
|
+
version: 0.0.1
|
68
|
+
type: :runtime
|
69
|
+
version_requirements: *id003
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: shoulda
|
72
|
+
prerelease: false
|
73
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
58
74
|
none: false
|
59
75
|
requirements:
|
60
76
|
- - ">="
|
@@ -64,7 +80,7 @@ dependencies:
|
|
64
80
|
- 0
|
65
81
|
version: "0"
|
66
82
|
type: :development
|
67
|
-
version_requirements: *
|
83
|
+
version_requirements: *id004
|
68
84
|
description: Characterize the relationship between "attributes" (getters/setters) of instances of a class
|
69
85
|
email: seamus@abshere.net
|
70
86
|
executables: []
|