attr_hash_accessor 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +4 -0
- data/lib/attr_hash_accessor.rb +7 -0
- data/lib/attr_hash_accessor/version.rb +1 -1
- data/spec/attr_hash_accessor_spec.rb +15 -0
- metadata +4 -4
data/CHANGELOG.md
CHANGED
data/lib/attr_hash_accessor.rb
CHANGED
@@ -18,6 +18,13 @@ module AttrHashAccessor
|
|
18
18
|
@attributes = self.class.default.stringify_keys.merge(val.stringify_keys)
|
19
19
|
end
|
20
20
|
|
21
|
+
def attributes
|
22
|
+
@attributes.keys.each_with_object({}) do |key, attrs|
|
23
|
+
next unless respond_to?(key)
|
24
|
+
attrs[key] = __send__(key)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
21
28
|
def persisted?
|
22
29
|
false
|
23
30
|
end
|
@@ -75,4 +75,19 @@ describe AttrHashAccessor do
|
|
75
75
|
expect(my_klass.new(bar: 'val').bar).to eq 'val'
|
76
76
|
end
|
77
77
|
end
|
78
|
+
|
79
|
+
describe '#attributes' do
|
80
|
+
let(:my_klass) do
|
81
|
+
Class.new do
|
82
|
+
include AttrHashAccessor
|
83
|
+
attr_hash_accessor :foo
|
84
|
+
attr_hash_reader :bar
|
85
|
+
attr_hash_writer :buzz
|
86
|
+
end
|
87
|
+
end
|
88
|
+
let(:my_obj) { my_klass.new(foo: 'foo', bar: 'bar', buzz: 'buzz') }
|
89
|
+
subject { my_obj.attributes }
|
90
|
+
|
91
|
+
it { should == {'foo' => 'foo', 'bar' => 'bar'} }
|
92
|
+
end
|
78
93
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attr_hash_accessor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
@@ -107,7 +107,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
107
107
|
version: '0'
|
108
108
|
segments:
|
109
109
|
- 0
|
110
|
-
hash:
|
110
|
+
hash: 175363436218142031
|
111
111
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
112
|
none: false
|
113
113
|
requirements:
|
@@ -116,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
116
|
version: '0'
|
117
117
|
segments:
|
118
118
|
- 0
|
119
|
-
hash:
|
119
|
+
hash: 175363436218142031
|
120
120
|
requirements: []
|
121
121
|
rubyforge_project:
|
122
122
|
rubygems_version: 1.8.24
|