galetahub-enum_field 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/README.rdoc +9 -7
- data/lib/enum_field/builder.rb +7 -2
- data/lib/enum_field/define_enum.rb +2 -2
- data/lib/enum_field/version.rb +1 -1
- 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: 96da53c393009eaee6d98a66b4107c243577a44c
         | 
| 4 | 
            +
              data.tar.gz: 7c17bffc0d29bfdb5b8399341031bb296f287835
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 4ae37aca910cbef3b82a0a67ea4003368c5b832654fcd404b9e45d4e986bbe5f371c2b10f2381c9448d92c064e2111ca487b09cb2937c39d94da306b7ba8a764
         | 
| 7 | 
            +
              data.tar.gz: fca89c19f39e43eadca5395b860d3d3fc9d6b8a669dd0ad37820d5511a25e1a6bce8f86f442aa95e716ac6c69edb641e5667b70129ef8bb5786dbafae71e1e70
         | 
    
        data/README.rdoc
    CHANGED
    
    | @@ -7,6 +7,10 @@ | |
| 7 7 | 
             
            Enables Active Record attributes to point to enum like objects, by saving in your database
         | 
| 8 8 | 
             
            only an integer ID.
         | 
| 9 9 |  | 
| 10 | 
            +
            == INSTALL:
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              gem 'galetahub-enum_field', require: 'enum_field'
         | 
| 13 | 
            +
             | 
| 10 14 |  | 
| 11 15 | 
             
            == FEATURES:
         | 
| 12 16 |  | 
| @@ -27,7 +31,7 @@ several options. | |
| 27 31 | 
             
            * You can use a string to identify, for instance, the role.
         | 
| 28 32 | 
             
            * You can use an id to identify the role.
         | 
| 29 33 |  | 
| 30 | 
            -
            If you are not  | 
| 34 | 
            +
            If you are not comfortable with any of this options, maybe +enum_field+ is an answer for you.
         | 
| 31 35 |  | 
| 32 36 | 
             
            == BASIC USAGE:
         | 
| 33 37 |  | 
| @@ -54,6 +58,9 @@ If you are not confortable with any of this options, maybe +enum_field+ is an an | |
| 54 58 | 
             
              user.role = Role.manager
         | 
| 55 59 | 
             
              user.role_id == Role.manager.id  #will be true
         | 
| 56 60 |  | 
| 61 | 
            +
              Role.manager.name # :manager
         | 
| 62 | 
            +
              user.role.name # :manager
         | 
| 63 | 
            +
             | 
| 57 64 | 
             
              User.first.role.id == User.first.role_id  #will be true
         | 
| 58 65 |  | 
| 59 66 | 
             
            Your enum classes can have all the methods you need:
         | 
| @@ -108,7 +115,7 @@ The library also mimics has_many :through behavior, for cases such as: | |
| 108 115 |  | 
| 109 116 | 
             
              class UserRole < ActiveRecord::Base
         | 
| 110 117 | 
             
                extend EnumField::EnumeratedAttribute
         | 
| 111 | 
            -
             | 
| 118 | 
            +
             | 
| 112 119 | 
             
                belongs_to :user
         | 
| 113 120 | 
             
                enumerated_attribute :role
         | 
| 114 121 | 
             
              end
         | 
| @@ -129,11 +136,6 @@ The library also mimics has_many :through behavior, for cases such as: | |
| 129 136 |  | 
| 130 137 | 
             
            * activerecord
         | 
| 131 138 |  | 
| 132 | 
            -
             | 
| 133 | 
            -
            == INSTALL:
         | 
| 134 | 
            -
             | 
| 135 | 
            -
              gem 'galetahub-enum_field', :require => 'enum_field'
         | 
| 136 | 
            -
             | 
| 137 139 | 
             
            == LICENSE:
         | 
| 138 140 |  | 
| 139 141 | 
             
            (The MIT License)
         | 
    
        data/lib/enum_field/builder.rb
    CHANGED
    
    | @@ -15,6 +15,7 @@ module EnumField | |
| 15 15 | 
             
                def member(name, options = {})
         | 
| 16 16 | 
             
                  obj, candidate_id = process_options(options)
         | 
| 17 17 | 
             
                  assign_id(obj, candidate_id)
         | 
| 18 | 
            +
                  assign_name(obj, name)
         | 
| 18 19 | 
             
                  define_in_meta(name) { obj }
         | 
| 19 20 | 
             
                  save(name, obj)
         | 
| 20 21 | 
             
                  obj.freeze
         | 
| @@ -34,9 +35,9 @@ module EnumField | |
| 34 35 |  | 
| 35 36 | 
             
                def find_by_id(id)
         | 
| 36 37 | 
             
                  case id
         | 
| 37 | 
            -
                  when Integer, String, Float, Fixnum then | 
| 38 | 
            +
                  when Integer, String, Float, Fixnum then
         | 
| 38 39 | 
             
                    @id2obj[id.to_i]
         | 
| 39 | 
            -
                  when Array then | 
| 40 | 
            +
                  when Array then
         | 
| 40 41 | 
             
                    id.inject([]) do |items, value|
         | 
| 41 42 | 
             
                      if value && value.respond_to?(:to_i)
         | 
| 42 43 | 
             
                        items << @id2obj[value.to_i]
         | 
| @@ -62,6 +63,10 @@ module EnumField | |
| 62 63 | 
             
                  obj.instance_variable_set(:@id, id)
         | 
| 63 64 | 
             
                end
         | 
| 64 65 |  | 
| 66 | 
            +
                def assign_name(obj, name)
         | 
| 67 | 
            +
                  obj.instance_variable_set(:@name, name)
         | 
| 68 | 
            +
                end
         | 
| 69 | 
            +
             | 
| 65 70 | 
             
                def new_id(candidate)
         | 
| 66 71 | 
             
                  validate_candidate_id(candidate)
         | 
| 67 72 | 
             
                  candidate || find_next_id
         | 
    
        data/lib/enum_field/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: galetahub-enum_field
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.4.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Igor Galeta
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2015- | 
| 12 | 
            +
            date: 2015-12-11 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies: []
         | 
| 14 14 | 
             
            description: Enables Active Record attributes to point to enum like objects, by saving
         | 
| 15 15 | 
             
              in your database only an integer ID
         |