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.
@@ -1,3 +1,7 @@
1
+ ## 0.0.3 (Oct 17, 2012)
2
+
3
+ * add `#attributes`, returns all filtered attributes *takkanm*
4
+
1
5
  ## 0.0.2 (Oct 04, 2012)
2
6
 
3
7
  * add `attr_hash_accessor`, defines both setter and getter *hibariya*
@@ -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
@@ -1,3 +1,3 @@
1
1
  module AttrHashAccessor
2
- VERSION = "0.0.2"
2
+ VERSION = '0.0.3'
3
3
  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.2
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-04 00:00:00.000000000 Z
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: 606188242904257753
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: 606188242904257753
119
+ hash: 175363436218142031
120
120
  requirements: []
121
121
  rubyforge_project:
122
122
  rubygems_version: 1.8.24