Sha256: f849aaccd90d9d56c0eee938daebc6a8e603254c5730bc50e03f717db333d4de

Contents?: true

Size: 844 Bytes

Versions: 4

Compression:

Stored size: 844 Bytes

Contents

module Swift
  class Attribute
    attr_reader :name, :field, :key, :serial

    def initialize scheme, name, options = {}
      @name      = name
      @default   = options.fetch(:default, nil)
      @field     = options.fetch(:field,   name)
      @key       = options.fetch(:key,     false)
      @serial    = options.fetch(:serial,  false)
      define_scheme_methods(scheme)
    end

    def default
      if @default.respond_to?(:call)
        @default.call
      elsif Swift.special_constant?(@default)
        @default
      else
        @default.dup
      end
    end

    def define_scheme_methods scheme
      scheme.class_eval <<-RUBY, __FILE__, __LINE__ + 1
        def #{name};        tuple.fetch(:#{field}, nil)   end
        def #{name}= value; tuple.store(:#{field}, value) end
      RUBY
    end
  end # Attribute
end # Swift

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
swift-0.6.1 lib/swift/attribute.rb
swift-0.6.0 lib/swift/attribute.rb
swift-0.5.1 lib/swift/attribute.rb
swift-0.5.0 lib/swift/attribute.rb