mongoid-indifferent-access 0.0.1 → 0.0.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/Gemfile.lock CHANGED
@@ -1,30 +1,29 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mongoid-indifferent-access (0.0.1)
4
+ mongoid-indifferent-access (0.0.3)
5
5
  mongoid
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
- activemodel (3.2.2)
11
- activesupport (= 3.2.2)
10
+ activemodel (3.2.7)
11
+ activesupport (= 3.2.7)
12
12
  builder (~> 3.0.0)
13
- activesupport (3.2.2)
13
+ activesupport (3.2.7)
14
14
  i18n (~> 0.6)
15
15
  multi_json (~> 1.0)
16
- bson (1.6.1)
17
- bson (1.6.1-java)
18
16
  builder (3.0.0)
19
17
  diff-lcs (1.1.3)
20
18
  i18n (0.6.0)
21
- mongo (1.6.1)
22
- bson (~> 1.6.1)
23
- mongoid (2.4.6)
19
+ mongoid (3.0.3)
24
20
  activemodel (~> 3.1)
25
- mongo (~> 1.3)
21
+ moped (~> 1.1)
22
+ origin (~> 1.0)
26
23
  tzinfo (~> 0.3.22)
27
- multi_json (1.1.0)
24
+ moped (1.2.0)
25
+ multi_json (1.3.6)
26
+ origin (1.0.6)
28
27
  rake (0.9.2.2)
29
28
  rspec (2.8.0)
30
29
  rspec-core (~> 2.8.0)
@@ -34,7 +33,7 @@ GEM
34
33
  rspec-expectations (2.8.0)
35
34
  diff-lcs (~> 1.1.2)
36
35
  rspec-mocks (2.8.0)
37
- tzinfo (0.3.32)
36
+ tzinfo (0.3.33)
38
37
 
39
38
  PLATFORMS
40
39
  java
@@ -2,39 +2,52 @@ module Mongoid
2
2
  module Extensions
3
3
  module Hash
4
4
  module IndifferentAccess
5
- VERSION = "0.0.1"
5
+
6
+ VERSION = "0.0.3"
6
7
 
7
8
  def self.included(klass)
8
9
  klass.class_eval do
9
- # @override Mongoid::Field
10
+
10
11
  def self.field(name, options={})
11
12
  field = super(name, options)
12
13
 
13
- # why oh why does sometimes Hash != Hash? something with my environment maybe?
14
- # tried ruby 1.9.2-p290 and jruby 1.6.6 (1.9 mode), so we also try checking the class name
15
- if options[:type] == Hash || options[:type].name =~ /Hash/
16
- getter_name = name.is_a?(Symbol) ? name : name.intern
17
- setter_name = "#{getter_name}=".intern
18
-
19
- define_method(getter_name) do
20
- val = super()
21
- unless val.nil? || val.is_a?(HashWithIndifferentAccess)
22
- wrapped_hash = val.with_indifferent_access
23
- self.send(setter_name, wrapped_hash)
24
- val = wrapped_hash
25
- end
26
- val
27
- end
14
+ if options[:type].name == 'Hash'
15
+ getter_name = name.to_sym
16
+ setter_name = "#{getter_name}=".to_sym
17
+
18
+ hia_define_getter(getter_name, setter_name)
19
+ hia_define_setter(setter_name)
28
20
 
29
- define_method(setter_name) do |hash|
30
- unless hash.nil? || hash.is_a?(HashWithIndifferentAccess)
31
- hash = hash.with_indifferent_access
32
- end
33
- super(hash)
21
+ descendants.each do |subclass|
22
+ subclass.hia_define_getter(getter_name, setter_name)
23
+ subclass.hia_define_setter(setter_name)
34
24
  end
35
25
  end
26
+
36
27
  field
37
28
  end
29
+
30
+ def self.hia_define_getter(getter_name, setter_name)
31
+ define_method(getter_name) do
32
+ val = super()
33
+ unless val.nil? || val.is_a?(HashWithIndifferentAccess)
34
+ wrapped_hash = val.with_indifferent_access
35
+ self.send(setter_name, wrapped_hash)
36
+ val = wrapped_hash
37
+ end
38
+ val
39
+ end
40
+ end
41
+
42
+ def self.hia_define_setter(setter_name)
43
+ define_method(setter_name) do |hash|
44
+ unless hash.nil? || hash.is_a?(HashWithIndifferentAccess)
45
+ hash = hash.with_indifferent_access
46
+ end
47
+ super(hash)
48
+ end
49
+ end
50
+
38
51
  end
39
52
  end
40
53
  end
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
13
13
  ## If your rubyforge_project name is different, then edit it and comment out
14
14
  ## the sub! line in the Rakefile
15
15
  s.name = 'mongoid-indifferent-access'
16
- s.version = '0.0.1'
17
- s.date = '2012-03-13'
16
+ s.version = '0.0.3'
17
+ s.date = '2012-08-08'
18
18
  s.rubyforge_project = 'mongoid-indifferent-access'
19
19
 
20
20
  ## Make sure your summary is short. The description may be as long
@@ -62,6 +62,8 @@ Gem::Specification.new do |s|
62
62
  spec/mongoid-indifferent-access/indifferent_access_spec.rb
63
63
  spec/mongoid.yml
64
64
  spec/spec_helper.rb
65
+ spec/support/guitar.rb
66
+ spec/support/mandalin.rb
65
67
  ]
66
68
  # = MANIFEST =
67
69
 
@@ -1,43 +1,71 @@
1
1
  require 'spec_helper'
2
- require 'mongoid_indifferent_access'
3
- require 'mongoid'
4
-
5
- # mocking some of what Mongoid::Document would provide
6
- # so the spec doesn't require having MongoDB running
7
- class MockSuper
8
- attr_accessor :config
9
- def self.field(name, options={})
10
- nil
11
- end
12
- end
13
-
14
- class Guitar < MockSuper
15
- include Mongoid::Extensions::Hash::IndifferentAccess
16
-
17
- field :config, :type => Hash
18
- end
2
+ require 'support/guitar'
3
+ require 'support/mandalin'
19
4
 
20
5
  module Mongoid::Extensions::Hash
21
6
 
22
7
  describe IndifferentAccess do
23
- subject {
24
- g = Guitar.new
25
- g.config = {:value => 123}
26
- g
27
- }
8
+
9
+ before :each do
10
+ @subject = Guitar.new
11
+ @subject.config = {:value => 123}
12
+ end
28
13
 
29
14
  it "returns a value given a String as the key" do
30
- subject.config["value"].should eq(123)
15
+ @subject.config["value"].should eq(123)
31
16
  end
32
17
 
33
18
  it "returns a value given a Symbol as the key" do
34
- subject.config[:value].should eq(123)
19
+ @subject.config[:value].should eq(123)
35
20
  end
36
21
 
37
22
  it "returns nil given a non-existing key" do
38
- subject.config[:non_existant].should be_nil
23
+ @subject.config[:non_existant].should be_nil
24
+ end
25
+
26
+ describe 'subclasses' do
27
+
28
+ before :each do
29
+ @sub_subject = Mandalin.new
30
+ @sub_subject.config = {:value => 123}
31
+ end
32
+
33
+ it "returns a value given a String as the key" do
34
+ @sub_subject.config["value"].should eq(123)
35
+ end
36
+
37
+ it "returns a value given a Symbol as the key" do
38
+ @sub_subject.config[:value].should eq(123)
39
+ end
40
+
41
+ it "returns nil given a non-existing key" do
42
+ @sub_subject.config[:non_existant].should be_nil
43
+ end
44
+
45
+ describe 'reload superclass' do
46
+
47
+ before :each do
48
+ load 'support/guitar.rb'
49
+ @sub_subject = Mandalin.new
50
+ @sub_subject.config = {:value => 123}
51
+ end
52
+
53
+ it "returns a value given a String as the key" do
54
+ @sub_subject.config["value"].should eq(123)
55
+ end
56
+
57
+ it "returns a value given a Symbol as the key" do
58
+ @sub_subject.config[:value].should eq(123)
59
+ end
60
+
61
+ it "returns nil given a non-existing key" do
62
+ @sub_subject.config[:non_existant].should be_nil
63
+ end
64
+
65
+ end
66
+
39
67
  end
40
68
 
41
69
  end
42
70
 
43
- end
71
+ end
data/spec/spec_helper.rb CHANGED
@@ -13,4 +13,4 @@
13
13
  require 'rspec/autorun'
14
14
  ROOT = File.expand_path('../..', __FILE__)
15
15
  Dir[File.join(ROOT, "spec/support/**/*.rb")].each {|f| require f}
16
- $LOAD_PATH.unshift(File.expand_path('lib', ROOT))
16
+ $LOAD_PATH.unshift(File.expand_path('lib', ROOT))
@@ -0,0 +1,9 @@
1
+ require 'mongoid'
2
+ require 'mongoid_indifferent_access'
3
+
4
+ class Guitar
5
+ include Mongoid::Document
6
+ include Mongoid::Extensions::Hash::IndifferentAccess
7
+
8
+ field :config, :type => Hash
9
+ end
@@ -0,0 +1,2 @@
1
+ class Mandalin < Guitar
2
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-indifferent-access
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
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: 2012-03-13 00:00:00.000000000Z
12
+ date: 2012-08-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mongoid
16
- requirement: &2176859440 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2176859440
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: rake
27
- requirement: &2176858660 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *2176858660
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: rspec
38
- requirement: &2176857780 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,7 +53,12 @@ dependencies:
43
53
  version: '0'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *2176857780
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  description: A Mongoid Hash extension enabling 'indifferent access' so you can access
48
63
  keys using Strings or Symbols.
49
64
  email: craig@mindscratch.org
@@ -60,6 +75,8 @@ files:
60
75
  - spec/mongoid-indifferent-access/indifferent_access_spec.rb
61
76
  - spec/mongoid.yml
62
77
  - spec/spec_helper.rb
78
+ - spec/support/guitar.rb
79
+ - spec/support/mandalin.rb
63
80
  homepage: https://github.com/mindscratch/mongoid-indifferent-access
64
81
  licenses: []
65
82
  post_install_message:
@@ -81,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
98
  version: '0'
82
99
  requirements: []
83
100
  rubyforge_project: mongoid-indifferent-access
84
- rubygems_version: 1.8.11
101
+ rubygems_version: 1.8.24
85
102
  signing_key:
86
103
  specification_version: 2
87
104
  summary: A Mongoid Hash extension enabling 'indifferent access' so you can access