kwattr 0.3.0 → 0.4.0
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/benchmark.rb +2 -2
 - data/lib/kwattr.rb +12 -9
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: dff8a0f557944d7eb7a901f75edc60091b01094e
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 6eae305b4eadccfcb92cda575eeaf09c8a71d2b2
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 17e68381d077e09fe0d7fd72828b2a1cd8dbab34c8010f43f679df76dac63e43a363f9aea9ee8e339295f8108b6266fff8bd958b782b299590867fd2f135a5fe
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: b82fcba69e07b3b247b9411fd400f5fa28ad9ed8e901b0d61623ec96750214cb5478e76d965af4f50eb4a4f039abc53ff74ea98907e9000f2e12b99f2f7e4941
         
     | 
    
        data/benchmark.rb
    CHANGED
    
    
    
        data/lib/kwattr.rb
    CHANGED
    
    | 
         @@ -1,26 +1,26 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            class KWAttr < Module
         
     | 
| 
       2 
     | 
    
         
            -
              VERSION = "0. 
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
              attr_reader :required_attrs, :defaults
         
     | 
| 
      
 2 
     | 
    
         
            +
              VERSION = "0.4.0"
         
     | 
| 
       5 
3 
     | 
    
         | 
| 
       6 
4 
     | 
    
         
             
              def initialize
         
     | 
| 
       7 
     | 
    
         
            -
                @ 
     | 
| 
      
 5 
     | 
    
         
            +
                @required = []
         
     | 
| 
       8 
6 
     | 
    
         
             
                @defaults = {}
         
     | 
| 
       9 
7 
     | 
    
         
             
              end
         
     | 
| 
       10 
8 
     | 
    
         | 
| 
       11 
9 
     | 
    
         
             
              def initializer(attrs, opts)
         
     | 
| 
       12 
     | 
    
         
            -
                required_attrs =  
     | 
| 
       13 
     | 
    
         
            -
                defaults =  
     | 
| 
      
 10 
     | 
    
         
            +
                required_attrs = @required
         
     | 
| 
      
 11 
     | 
    
         
            +
                defaults = @defaults
         
     | 
| 
       14 
12 
     | 
    
         
             
                required_attrs.concat(attrs).uniq!
         
     | 
| 
       15 
13 
     | 
    
         
             
                defaults.merge!(opts)
         
     | 
| 
      
 14 
     | 
    
         
            +
                iv_cache = Hash.new { |h, k| h[k] = :"@#{k}" }
         
     | 
| 
       16 
15 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
                $VERBOSE = false
         
     | 
| 
      
 16 
     | 
    
         
            +
                verbose, $VERBOSE = $VERBOSE, false
         
     | 
| 
       18 
17 
     | 
    
         
             
                define_method :initialize do |*args, **kwargs|
         
     | 
| 
       19 
18 
     | 
    
         
             
                  required = required_attrs.dup
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
       20 
20 
     | 
    
         
             
                  defaults.merge(kwargs).each_pair do |key, value|
         
     | 
| 
       21 
21 
     | 
    
         
             
                    next unless required.delete(key) || defaults.key?(key)
         
     | 
| 
       22 
22 
     | 
    
         
             
                    kwargs.delete(key)
         
     | 
| 
       23 
     | 
    
         
            -
                    instance_variable_set  
     | 
| 
      
 23 
     | 
    
         
            +
                    instance_variable_set iv_cache[key], value
         
     | 
| 
       24 
24 
     | 
    
         
             
                  end
         
     | 
| 
       25 
25 
     | 
    
         | 
| 
       26 
26 
     | 
    
         
             
                  unless required.empty?
         
     | 
| 
         @@ -41,9 +41,12 @@ class KWAttr < Module 
     | 
|
| 
       41 
41 
     | 
    
         | 
| 
       42 
42 
     | 
    
         
             
                  super(*args)
         
     | 
| 
       43 
43 
     | 
    
         
             
                end
         
     | 
| 
       44 
     | 
    
         
            -
                $VERBOSE =  
     | 
| 
      
 44 
     | 
    
         
            +
                $VERBOSE = verbose
         
     | 
| 
       45 
45 
     | 
    
         
             
              end
         
     | 
| 
       46 
46 
     | 
    
         | 
| 
      
 47 
     | 
    
         
            +
              def inspect
         
     | 
| 
      
 48 
     | 
    
         
            +
                "<KWAttr:#{'%#016x'%(object_id<<1)} @required=#{@required.inspect}, @defaults=#{@defaults.inspect}>"
         
     | 
| 
      
 49 
     | 
    
         
            +
              end
         
     | 
| 
       47 
50 
     | 
    
         
             
            end
         
     | 
| 
       48 
51 
     | 
    
         | 
| 
       49 
52 
     | 
    
         
             
            class Module
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: kwattr
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.4.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - "Étienne Barrié"
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2015-06- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2015-06-23 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: bundler
         
     |