dynamic_attribute_declaration 0.1.1 → 0.1.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 823bbe01675f8328ed7d7cba95a42611ba505a2b
4
- data.tar.gz: f685a0d12105f87c69d03a7353e198ff56a96fa8
3
+ metadata.gz: a06b5b243da301f6a1fad227bc3f994626de2695
4
+ data.tar.gz: 4985de29d17066ec9edbbd3ab66415f475056435
5
5
  SHA512:
6
- metadata.gz: 3800c7f6ab5c0815dc931f2733813936743b664318f5b57e3967f3346d07d272199b2c152964a67d2adacc2281b8c5b8c2927183a8442bc76879215e28b53527
7
- data.tar.gz: e0abe7bd669032fbdfa3824b75277720ada4726885c68649fe881d4aedc475f9e20c86d6264c09dcbdfec9909651679f9b09a938c815ce7ef48871c7e08a846f
6
+ metadata.gz: c101d74f7db8e5faf8ba74964e71664d056f35378d80c6814838bb518b4fd025b3d474ab2c01df19e5cfc15eed8eff72f4c44d9302ac90de1f598dd1d38de50b
7
+ data.tar.gz: 54e6fd2554b07497bba47dc9bc0c5099d9f4151eeaf5592ee5abe564db9a0363d7deb191531ebb54480121799c173885ec0a3b4ec0749113594161c2c709e316
@@ -48,20 +48,22 @@ module DynamicAttributeDeclaration
48
48
 
49
49
  def attrs_on_for attr_name
50
50
  attr = _dynamic_attrs[attr_name]
51
- rtn = {}
52
- attr.each do |a|
53
- if a.key? :on
54
- obj = a[:on]
55
- obj.each do |key, value|
56
- if rtn.key? key
57
- rtn[key].push(value).flatten!
58
- else
59
- rtn[key] = value
51
+ if attr && !attr.empty?
52
+ rtn = {}
53
+ attr.each do |a|
54
+ if a.key? :on
55
+ obj = a[:on]
56
+ obj.each do |key, value|
57
+ if rtn.key? key
58
+ rtn[key].push(value).flatten!.uniq!
59
+ else
60
+ rtn[key] = value
61
+ end
60
62
  end
61
63
  end
62
64
  end
65
+ rtn
63
66
  end
64
- rtn
65
67
  end
66
68
 
67
69
  def attrs_for state=nil, device=nil
@@ -1,3 +1,3 @@
1
1
  module DynamicAttributeDeclaration
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -101,7 +101,10 @@ describe "BASE TESTS" do
101
101
  name: { on: :foo }
102
102
  },
103
103
  {
104
- name: { on: :bar }
104
+ name: { on: [:bar] }
105
+ },
106
+ {
107
+ name: { on: [:foo, :bar] }
105
108
  }
106
109
  ]
107
110
  cls.define_attrs @definition
@@ -111,7 +114,34 @@ describe "BASE TESTS" do
111
114
  it "Should hold a hash for the defines on" do
112
115
  expect(cls._dynamic_attrs[:name]).not_to eq nil
113
116
  expect(cls._dynamic_attrs[:name].class).to eq Array
114
- expect(cls._dynamic_attrs[:name].length).to eq 2
117
+ expect(cls._dynamic_attrs[:name].length).to eq 3
118
+ end
119
+ end
120
+
121
+ describe 'attrs_on_for' do
122
+ it "Should return right type" do
123
+ expect(cls.attrs_on_for(:name)).not_to eq nil
124
+ expect(cls.attrs_on_for(:name).class).to eq Hash
125
+ expect(cls.attrs_on_for(:lala)).to eq nil
126
+ end
127
+
128
+ it 'Should return unique states' do
129
+ obj = cls.attrs_on_for(:name)
130
+ count = {}
131
+
132
+ obj.keys.each do |state|
133
+ obj[state].each do |attr_name|
134
+ id = "#{state}-#{attr_name}"
135
+ puts "key #{id}"
136
+ if count.key? id
137
+ count[id] += 1
138
+ else
139
+ count[id] = 1
140
+ end
141
+ end
142
+ end
143
+
144
+ expect(count.select { |k,v| v != 1 }).to eq({})
115
145
  end
116
146
  end
117
147
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamic_attribute_declaration
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikkel Wied Frederiksen