Class: Meteor::AttributeMap

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

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAttributeMap #initialize(attr_map) ⇒ AttributeMap

initializer (イニシャライザ)

Overloads:



15
16
17
18
19
20
21
22
23
24
# File 'lib/meteor/attribute_map.rb', line 15

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.



123
124
125
# File 'lib/meteor/attribute_map.rb', line 123

def map
  @map
end

#recordableObject

Returns the value of attribute recordable.



124
125
126
# File 'lib/meteor/attribute_map.rb', line 124

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 (属性値)



142
143
144
# File 'lib/meteor/attribute_map.rb', line 142

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 (属性値)



132
133
134
# File 'lib/meteor/attribute_map.rb', line 132

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 (属性の変更状況)



107
108
109
110
111
# File 'lib/meteor/attribute_map.rb', line 107

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

#delete(name) ⇒ Object

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

Parameters:

  • name

    attribute name (属性名)



96
97
98
99
100
101
# File 'lib/meteor/attribute_map.rb', line 96

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 (属性値)



86
87
88
89
90
# File 'lib/meteor/attribute_map.rb', line 86

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

#namesArray

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

Returns:

  • (Array)

    attribute name array (属性名配列)



77
78
79
# File 'lib/meteor/attribute_map.rb', line 77

def names
  @map.keys
end

#removed(name) ⇒ true, false

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

Returns:

  • (true, false)

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



117
118
119
120
121
# File 'lib/meteor/attribute_map.rb', line 117

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 (属性値)



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/meteor/attribute_map.rb', line 53

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