class Meteor::AttributeMap

Attribute Map Class (属性マップクラス)

Attributes

map[RW]
recordable[RW]

Public Class Methods

new(*args) click to toggle source

initializer (イニシャライザ) @overload initialize @overload initialize(attr_map)

@param [Meteor::AttributeMap] attr_map attribute map (属性マップ)
# File lib/meteor.rb, line 611
def initialize(*args)
  case args.length
    when ZERO
      initialize_0
    when ONE
      initialize_1(args[0])
    else
      raise ArgumentError
  end
end

Public Instance Methods

[](name) click to toggle source

get attribute value using attribute name (属性名で属性値を取得する)

@param [String,Symbol] name attribute name (属性名) @return [String] attribute value (属性値)

# File lib/meteor.rb, line 739
def [](name)
  fetch(name)
end
[]=(name, value) click to toggle source

set a couple of attribute name and attribute value (属性名と属性値を対としてセットする)

@param [String,Symbol] name attribute name (属性名) @param [String] value attribute value (属性値)

# File lib/meteor.rb, line 729
def []=(name, value)
  store(name, value)
end
changed(name) click to toggle source

get update flag of attribute using attribute name (属性名で属性の変更フラグを取得する) @return [true,false] update flag of attribute (属性の変更状況)

# File lib/meteor.rb, line 704
def changed(name)
  if @map[name]
    @map[name].changed
  end
end
delete(name) click to toggle source

delete attribute using attribute name (属性名に対応した属性を削除する) @param name attribute name (属性名)

# File lib/meteor.rb, line 693
def delete(name)
  if @recordable && @map[name]
    @map[name].removed = true
    @map[name].changed = false
  end
end
fetch(name) click to toggle source

get attribute value using attribute name (属性名で属性値を取得する) @param [String,Symbol] name attribute name (属性名) @return [String] attribute value (属性値)

# File lib/meteor.rb, line 683
def fetch(name)
  if @map[name] && !@map[name].removed
    @map[name].value
  end
end
names() click to toggle source

get attribute name array (属性名配列を取得する) @return [Array] attribute name array (属性名配列)

# File lib/meteor.rb, line 674
def names
  @map.keys
end
removed(name) click to toggle source

get delete flag of attribute using attribute name (属性名で属性の削除状況を取得する) @return [true,false] delete flag of attribute (属性の削除状況)

# File lib/meteor.rb, line 714
def removed(name)
  if @map[name]
    @map[name].removed
  end
end
store(name, value) click to toggle source

set a couple of attribute name and attribute value (属性名と属性値を対としてセットする) @param [String,Symbol] name attribute name (属性名) @param [String] value attribute value (属性値)

# File lib/meteor.rb, line 649
def store(name, value)

  if !@map[name]
    attr = Attribute.new
    attr.name = name
    attr.value = value
    if @recordable
      attr.changed = true
      attr.removed = false
    end
    @map[name] = attr
  else
    attr = @map[name]
    if @recordable && attr.value != value
      attr.changed = true
      attr.removed = false
    end
    attr.value = value
  end
end

Private Instance Methods

initialize_0() click to toggle source

initializer (イニシャライザ)

# File lib/meteor.rb, line 625
def initialize_0
  @map = Hash.new
  @recordable = false
end
initialize_1(attr_map) click to toggle source

initializer (イニシャライザ) @param [Meteor::AttributeMap] attr_map attribute map (属性マップ)

# File lib/meteor.rb, line 636
def initialize_1(attr_map)
  #@map = Marshal.load(Marshal.dump(attr_map.map))
  @map = attr_map.map.dup
  @recordable = attr_map.recordable
end