easy_attributes 0.1.2 → 0.1.3
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.
- data/README.rdoc +1 -1
- data/VERSION +1 -1
- data/easy_attributes.gemspec +2 -2
- data/lib/easy_attributes.rb +16 -6
- metadata +4 -4
    
        data/README.rdoc
    CHANGED
    
    | @@ -10,7 +10,7 @@ First, install this from rubygems.org | |
| 10 10 | 
             
             gem install easy_attributes
         | 
| 11 11 |  | 
| 12 12 | 
             
            Next, you need to configure your app to use it, by either:
         | 
| 13 | 
            -
             require 'rubygems'                 #  | 
| 13 | 
            +
             require 'rubygems'                 # Ruby application, no framework
         | 
| 14 14 | 
             
             require 'easy_attributes'          #
         | 
| 15 15 |  | 
| 16 16 | 
             
             config.gem 'easy_attributes'       # Rails 2.x, in your ./config/environment.rb
         | 
    
        data/VERSION
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            0.1. | 
| 1 | 
            +
            0.1.3
         | 
    
        data/easy_attributes.gemspec
    CHANGED
    
    | @@ -5,11 +5,11 @@ | |
| 5 5 |  | 
| 6 6 | 
             
            Gem::Specification.new do |s|
         | 
| 7 7 | 
             
              s.name = %q{easy_attributes}
         | 
| 8 | 
            -
              s.version = "0.1. | 
| 8 | 
            +
              s.version = "0.1.3"
         | 
| 9 9 |  | 
| 10 10 | 
             
              s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
         | 
| 11 11 | 
             
              s.authors = ["Allen Fair"]
         | 
| 12 | 
            -
              s.date = %q{2010- | 
| 12 | 
            +
              s.date = %q{2010-08-06}
         | 
| 13 13 | 
             
              s.description = %q{Easy Attributes is a Ruby DSL to give more control to attributes.}
         | 
| 14 14 | 
             
              s.email = %q{allen.fair@gmail.com}
         | 
| 15 15 | 
             
              s.extra_rdoc_files = [
         | 
    
        data/lib/easy_attributes.rb
    CHANGED
    
    | @@ -44,6 +44,14 @@ module EasyAttributes | |
| 44 44 | 
             
                  @@attributes
         | 
| 45 45 | 
             
                end
         | 
| 46 46 |  | 
| 47 | 
            +
                # Returns the value table: 
         | 
| 48 | 
            +
                #   values[:name][:rec][:setting] = {:word, :description, :value}
         | 
| 49 | 
            +
                #   values[:name][:sym][:setting] = value
         | 
| 50 | 
            +
                #   values[:name][:value]["value"] = :symbol
         | 
| 51 | 
            +
                def self.values
         | 
| 52 | 
            +
                  @@values
         | 
| 53 | 
            +
                end
         | 
| 54 | 
            +
                
         | 
| 47 55 | 
             
                # Loads a tab-delimted filename into the symbol table in format: 
         | 
| 48 56 | 
             
                # attribute value role symbolic_name short_description long_description (useful for "<option>" data)
         | 
| 49 57 | 
             
                # If a block is given, it should parse a file line and return an array of 
         | 
| @@ -57,7 +65,7 @@ module EasyAttributes | |
| 57 65 | 
             
                    @@values[col] = {:sym=>{}, :val=>{}, :rec=>{}} unless @@values.has_key?(col)
         | 
| 58 66 | 
             
                    @@values[col][:sym][symbol.to_sym] = val.to_i
         | 
| 59 67 | 
             
                    @@values[col][:val][val] = symbol.to_sym
         | 
| 60 | 
            -
                    @@values[col][:rec][symbol.to_sym] = {:word=>word, :description=>desc, :value=>val.to_i}
         | 
| 68 | 
            +
                    @@values[col][:rec][symbol.to_sym] = {:word=>word, :description=>desc.chomp, :value=>val.to_i}
         | 
| 61 69 | 
             
                    @@attributes[col.to_s] ||= {}
         | 
| 62 70 | 
             
                    @@attributes[col.to_s][symbol.to_sym] = val.to_i
         | 
| 63 71 | 
             
                  end
         | 
| @@ -87,10 +95,10 @@ module EasyAttributes | |
| 87 95 | 
             
                  name = "#{self.name}##{attribute}"
         | 
| 88 96 | 
             
                  EasyAttributes.add_definition( name, hash)
         | 
| 89 97 | 
             
                  code = ''
         | 
| 90 | 
            -
                  if EasyAttributes::Config.orm == :active_model
         | 
| 98 | 
            +
                  if EasyAttributes::Config.orm == :active_model && opt[:scope]
         | 
| 91 99 | 
             
                    validates_inclusion_of attribute, :in=>hash.values
         | 
| 92 100 | 
             
                    # Add named_scope (scope) for each value
         | 
| 93 | 
            -
                    hash.each { |k,v| code += " | 
| 101 | 
            +
                    hash.each { |k,v| code += "scope :#{k}, :conditions=>{:#{attribute}=>#{v.inspect}}\n" }
         | 
| 94 102 | 
             
                  else
         | 
| 95 103 | 
             
                    attr_accessor attribute
         | 
| 96 104 | 
             
                  end
         | 
| @@ -111,7 +119,7 @@ module EasyAttributes | |
| 111 119 | 
             
                  if EasyAttributes::Config.orm == :active_model
         | 
| 112 120 | 
             
                    code += %Q(
         | 
| 113 121 | 
             
                      def #{attribute}=(v)
         | 
| 114 | 
            -
                        self[:#{attribute}] = v.is_a?(Symbol) ? EasyAttributes.value_for_sym("#{ | 
| 122 | 
            +
                        self[:#{attribute}] = v.is_a?(Symbol) ? EasyAttributes.value_for_sym("#{name}", v) : v; 
         | 
| 115 123 | 
             
                      end
         | 
| 116 124 | 
             
                    )
         | 
| 117 125 | 
             
                  end
         | 
| @@ -196,11 +204,13 @@ module EasyAttributes | |
| 196 204 |  | 
| 197 205 | 
             
              # Returns the defined value for the given symbol and attribute
         | 
| 198 206 | 
             
              def self.value_for_sym(attribute, sym)
         | 
| 199 | 
            -
                EasyAttributes::Config.attributes[attribute][sym]
         | 
| 207 | 
            +
                EasyAttributes::Config.attributes[attribute][sym] or 
         | 
| 208 | 
            +
                  raise "EasyAttributes #{attribute} value :#{sym} not declared"
         | 
| 200 209 | 
             
              end
         | 
| 201 210 |  | 
| 202 211 | 
             
              # Returns the defined symbol for the given value on the attribute
         | 
| 203 212 | 
             
              def self.sym_for_value(attribute, value)
         | 
| 213 | 
            +
                return nil if value.nil?
         | 
| 204 214 | 
             
                EasyAttributes::Config.attributes[attribute].each {|k,v| return k if v==value}
         | 
| 205 215 | 
             
                raise "EasyAttribute #{attribute} symbol not found for #{value}"
         | 
| 206 216 | 
             
              end
         | 
| @@ -369,4 +379,4 @@ module EasyAttributes | |
| 369 379 | 
             
                value
         | 
| 370 380 | 
             
              end
         | 
| 371 381 |  | 
| 372 | 
            -
            end
         | 
| 382 | 
            +
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,13 +1,13 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: easy_attributes
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            -
              hash:  | 
| 4 | 
            +
              hash: 29
         | 
| 5 5 | 
             
              prerelease: false
         | 
| 6 6 | 
             
              segments: 
         | 
| 7 7 | 
             
              - 0
         | 
| 8 8 | 
             
              - 1
         | 
| 9 | 
            -
              -  | 
| 10 | 
            -
              version: 0.1. | 
| 9 | 
            +
              - 3
         | 
| 10 | 
            +
              version: 0.1.3
         | 
| 11 11 | 
             
            platform: ruby
         | 
| 12 12 | 
             
            authors: 
         | 
| 13 13 | 
             
            - Allen Fair
         | 
| @@ -15,7 +15,7 @@ autorequire: | |
| 15 15 | 
             
            bindir: bin
         | 
| 16 16 | 
             
            cert_chain: []
         | 
| 17 17 |  | 
| 18 | 
            -
            date: 2010- | 
| 18 | 
            +
            date: 2010-08-06 00:00:00 -04:00
         | 
| 19 19 | 
             
            default_executable: 
         | 
| 20 20 | 
             
            dependencies: []
         | 
| 21 21 |  |