Sha256: 0ccc0118b2ffb883f3431bafa8e1738493a59d7ebeb5e0781a821b3c7f218acb

Contents?: true

Size: 770 Bytes

Versions: 19

Compression:

Stored size: 770 Bytes

Contents

class Factory

  class AttributeDefinitionError < RuntimeError
  end
  
  class Attribute #:nodoc:

    attr_reader :name

    def initialize (name, static_value, lazy_block)
      name = name.to_sym

      if name.to_s =~ /=$/
        raise AttributeDefinitionError, 
          "factory_girl uses 'f.#{name.to_s.chop} value' syntax " +
          "rather than 'f.#{name} = value'" 
      end

      unless static_value.nil? || lazy_block.nil?
        raise AttributeDefinitionError, "Both value and block given"
      end

      @name         = name
      @static_value = static_value
      @lazy_block   = lazy_block
    end

    def value (proxy)
      if @lazy_block.nil?
        @static_value
      else
        @lazy_block.call(proxy)
      end
    end

  end

end

Version data entries

19 entries across 19 versions & 8 rubygems

Version Path
gabrielg-factory_girl-1.1.6 lib/factory_girl/attribute.rb
gabrielg-factory_girl-1.1.7 lib/factory_girl/attribute.rb
gabrielg-factory_girl-1.1.8 lib/factory_girl/attribute.rb
gabrielg-factory_girl-1.1.9 lib/factory_girl/attribute.rb
gabrielg-factory_girl-1.2.0 lib/factory_girl/attribute.rb
gabrielg-factory_girl-1.2.1 lib/factory_girl/attribute.rb
gabrielg-factory_girl-1.2.2 lib/factory_girl/attribute.rb
gsterndale-warrant-0.2.0 test/rails_root/vendor/gems/thoughtbot-factory_girl-1.1.5/lib/factory_girl/attribute.rb
gsterndale-warrant-0.3.0 test/rails_root/vendor/gems/thoughtbot-factory_girl-1.1.5/lib/factory_girl/attribute.rb
handcrafted-factory_girl-1.1.14 lib/factory_girl/attribute.rb
jrun-factory_girl-1.1.3.9999 lib/factory_girl/attribute.rb
multiplay-factory_girl-1.1.5 lib/factory_girl/attribute.rb
thoughtbot-factory_girl-1.1.3 lib/factory_girl/attribute.rb
thoughtbot-factory_girl-1.1.4 lib/factory_girl/attribute.rb
thoughtbot-factory_girl-1.1.5 lib/factory_girl/attribute.rb
threedaymonk-factory_girl-1.1.4 lib/factory_girl/attribute.rb
factory_girl-1.1.3 lib/factory_girl/attribute.rb
factory_girl-1.1.4 lib/factory_girl/attribute.rb
factory_girl-1.1.5 lib/factory_girl/attribute.rb