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 +4 -4
- data/lib/dynamic_attribute_declaration.rb +12 -10
- data/lib/dynamic_attribute_declaration/version.rb +1 -1
- data/spec/lib/base_spec.rb +32 -2
- metadata +1 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: a06b5b243da301f6a1fad227bc3f994626de2695
         | 
| 4 | 
            +
              data.tar.gz: 4985de29d17066ec9edbbd3ab66415f475056435
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 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 | 
            -
                   | 
| 52 | 
            -
             | 
| 53 | 
            -
                     | 
| 54 | 
            -
                       | 
| 55 | 
            -
             | 
| 56 | 
            -
                         | 
| 57 | 
            -
                          rtn | 
| 58 | 
            -
             | 
| 59 | 
            -
                           | 
| 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
         | 
    
        data/spec/lib/base_spec.rb
    CHANGED
    
    | @@ -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  | 
| 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 |  |