Class: Meteor::AttributeMap

Inherits:
Object
  • Object
show all
Defined in:
lib/meteor.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAttributeMap #initialize(attr_map) ⇒ AttributeMap

initializer (イニシャライザ)

Overloads:



600
601
602
603
604
605
606
607
608
609
# File 'lib/meteor.rb', line 600

def initialize(*args)
  case args.length
    when ZERO
      initialize_0
    when ONE
      initialize_1(args[0])
    else
      raise ArgumentError
  end
end

Instance Attribute Details

#mapObject

Returns the value of attribute map.



709
710
711
# File 'lib/meteor.rb', line 709

def map
  @map
end

#recordableObject

Returns the value of attribute recordable.



710
711
712
# File 'lib/meteor.rb', line 710

def recordable
  @recordable
end

Instance Method Details

#[](name) ⇒ String

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

Parameters:

  • name (String, Symbol)

    attribute name (属性名)

Returns:

  • (String)

    attribute value (属性値)



728
729
730
# File 'lib/meteor.rb', line 728

def [](name)
  fetch(name)
end

#[]=(name, value) ⇒ Object

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

Parameters:

  • name (String, Symbol)

    attribute name (属性名)

  • value (String)

    attribute value (属性値)



718
719
720
# File 'lib/meteor.rb', line 718

def []=(name, value)
  store(name, value)
end

#changed(name) ⇒ true, false

get update flag of attribute using attribute name (属性名で属性の変更フラグを取得する)

Returns:

  • (true, false)

    update flag of attribute (属性の変更状況)



693
694
695
696
697
# File 'lib/meteor.rb', line 693

def changed(name)
  if @map[name]
    @map[name].changed
  end
end

#delete(name) ⇒ Object

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

Parameters:

  • name

    attribute name (属性名)



682
683
684
685
686
687
# File 'lib/meteor.rb', line 682

def delete(name)
  if @recordable && @map[name]
    @map[name].removed = true
    @map[name].changed = false
  end
end

#fetch(name) ⇒ String

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

Parameters:

  • name (String, Symbol)

    attribute name (属性名)

Returns:

  • (String)

    attribute value (属性値)



672
673
674
675
676
# File 'lib/meteor.rb', line 672

def fetch(name)
  if @map[name] && !@map[name].removed
    @map[name].value
  end
end

#namesArray

get attribute name array (属性名配列を取得する)

Returns:

  • (Array)

    attribute name array (属性名配列)



663
664
665
# File 'lib/meteor.rb', line 663

def names
  @map.keys
end

#removed(name) ⇒ true, false

get delete flag of attribute using attribute name (属性名で属性の削除状況を取得する)

Returns:

  • (true, false)

    delete flag of attribute (属性の削除状況)



703
704
705
706
707
# File 'lib/meteor.rb', line 703

def removed(name)
  if @map[name]
    @map[name].removed
  end
end

#store(name, value) ⇒ Object

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

Parameters:

  • name (String, Symbol)

    attribute name (属性名)

  • value (String)

    attribute value (属性値)



638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
# File 'lib/meteor.rb', line 638

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