Sha256: d62810e55ae70af582ece0c285e414d7289de48fdf6225b8c377f7a62fe5d023

Contents?: true

Size: 769 Bytes

Versions: 3

Compression:

Stored size: 769 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
      @default.respond_to?(:call) ? @default.call : (@default.nil? ? nil : @default.dup)
    end

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
swift-0.4.3 lib/swift/attribute.rb
swift-0.4.2 lib/swift/attribute.rb
swift-0.4.1 lib/swift/attribute.rb