Class: Meteor::AttributeMap

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

Overview

属性マップクラス

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAttributeMap #initialize(attr_map) ⇒ AttributeMap

イニシャライザ

Overloads:



453
454
455
456
457
458
459
460
461
462
# File 'lib/meteor.rb', line 453

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.



573
574
575
# File 'lib/meteor.rb', line 573

def map
  @map
end

#recordableObject

Returns the value of attribute recordable.



574
575
576
# File 'lib/meteor.rb', line 574

def recordable
  @recordable
end

Instance Method Details

#[](name) ⇒ String

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

Parameters:

  • name (String)

    属性名

Returns:

  • (String)

    属性値



582
583
584
# File 'lib/meteor.rb', line 582

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

#changed(name) ⇒ true, false

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

Returns:

  • (true, false)

    属性の変更状況



557
558
559
560
561
# File 'lib/meteor.rb', line 557

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

#delete(name) ⇒ Object

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

Parameters:

  • name

    属性名



546
547
548
549
550
551
# File 'lib/meteor.rb', line 546

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)

    属性値



536
537
538
539
540
# File 'lib/meteor.rb', line 536

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

#namesArray

属性名配列を取得する

Returns:

  • (Array)

    属性名配列



523
524
525
526
527
528
529
# File 'lib/meteor.rb', line 523

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

#removed(name) ⇒ true, false

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

Returns:

  • (true, false)

    属性の削除状況



567
568
569
570
571
# File 'lib/meteor.rb', line 567

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

#store(name, value) ⇒ Object

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

Parameters:

  • name (String)

    属性名

  • value (String)

    属性値



495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
# File 'lib/meteor.rb', line 495

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