Class: Meteor::AttributeMap

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

Overview

属性マップクラス

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ AttributeMap

Returns a new instance of AttributeMap.



396
397
398
399
400
401
402
403
404
405
# File 'lib/meteor.rb', line 396

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.



521
522
523
# File 'lib/meteor.rb', line 521

def map
  @map
end

#recordableObject

Returns the value of attribute recordable.



522
523
524
# File 'lib/meteor.rb', line 522

def recordable
  @recordable
end

Instance Method Details

#[](name) ⇒ String

属性名で属性値を取得する

Parameters:

  • name (String)

    属性名

Returns:

  • (String)

    属性値



530
531
532
# File 'lib/meteor.rb', line 530

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

#changed(name) ⇒ TrueClass, FalseClass

属性名で属性の変更状況を取得する

Returns:

  • (TrueClass, FalseClass)

    属性の変更状況



504
505
506
507
508
# File 'lib/meteor.rb', line 504

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

#delete(name) ⇒ Object

属性名に対応した属性を削除する

Parameters:

  • name

    属性名



492
493
494
495
496
497
# File 'lib/meteor.rb', line 492

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

#fetch(name) ⇒ String

属性名で属性値を取得する

Parameters:

  • name (String)

    属性名

Returns:

  • (String)

    属性値



481
482
483
484
485
# File 'lib/meteor.rb', line 481

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

#namesArray

属性名配列を取得する

Returns:

  • (Array)

    属性名配列



467
468
469
470
471
472
473
# File 'lib/meteor.rb', line 467

def names
  if RUBY_VERSION < RUBY_VERSION_1_9_0
    @names
  else
    @map.keys
  end
end

#removed(name) ⇒ TrueClass, FalseClass

属性名で属性の削除状況を取得する

Returns:

  • (TrueClass, FalseClass)

    属性の削除状況



515
516
517
518
519
# File 'lib/meteor.rb', line 515

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

#store(name, value) ⇒ Object

属性名と属性値を対としてセットする

Parameters:

  • name (String)

    属性名

  • value (String)

    属性値



438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
# File 'lib/meteor.rb', line 438

def store(name,value)

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