Class: SoftLayer::DynamicAttribute::DynamicAttributeDefinition

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

Overview

The DynamicAttributeDefinition inner class is to collect and store information about how and when a sl_dynamic_attr should be updated. This class is an implementation detail of dynamic attributes and is not intended to be useful outside of that context.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute_name) ⇒ DynamicAttributeDefinition

Returns a new instance of DynamicAttributeDefinition

Raises:

  • (ArgumentError)


74
75
76
77
78
79
80
81
# File 'lib/softlayer/DynamicAttribute.rb', line 74

def initialize(attribute_name)
  raise ArgumentError if attribute_name.nil?
  raise ArgumentError if attribute_name.to_s.empty?

  @attribute_name = attribute_name;
  @update_block = Proc.new { nil; };
  @should_update_block = Proc.new { true; }
end

Instance Attribute Details

#attribute_nameObject (readonly)

the name of the attribute this definition is for



64
65
66
# File 'lib/softlayer/DynamicAttribute.rb', line 64

def attribute_name
  @attribute_name
end

#should_update_blockObject (readonly)

The block to call to see if the attribute needs to be updated.



72
73
74
# File 'lib/softlayer/DynamicAttribute.rb', line 72

def should_update_block
  @should_update_block
end

#update_blockObject (readonly)

The block to call in order to update the attribute. The return value of this block should be the new value of the attribute.



69
70
71
# File 'lib/softlayer/DynamicAttribute.rb', line 69

def update_block
  @update_block
end

Instance Method Details

#should_update?(&block) ⇒ Boolean

This method is used to provide behavior for the should_update_ predicate for the attribute

Returns:

  • (Boolean)


85
86
87
# File 'lib/softlayer/DynamicAttribute.rb', line 85

def should_update? (&block)
  @should_update_block = block
end

#to_update(&block) ⇒ Object

This method is used to provide the behavior for the update_! method for the attribute.



91
92
93
# File 'lib/softlayer/DynamicAttribute.rb', line 91

def to_update (&block)
  @update_block = block
end