Class: Anima::Attribute Private

Inherits:
Object
  • Object
show all
Includes:
Adamantium::Flat
Defined in:
lib/anima/attribute.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

An attribute

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Attribute

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize attribute

Parameters:

  • name (Symbol)


9
10
11
# File 'lib/anima/attribute.rb', line 9

def initialize(name)
  @name, @instance_variable_name = name, :"@#{name}"
end

Instance Attribute Details

#instance_variable_nameSymbol (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return instance variable name

Returns:

  • (Symbol)


21
22
23
# File 'lib/anima/attribute.rb', line 21

def instance_variable_name
  @instance_variable_name
end

#nameSymbol (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return attribute name

Returns:

  • (Symbol)


16
17
18
# File 'lib/anima/attribute.rb', line 16

def name
  @name
end

Instance Method Details

#get(object) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get attribute value from object

Parameters:

  • object (Object)

Returns:

  • (Object)


38
39
40
# File 'lib/anima/attribute.rb', line 38

def get(object)
  object.public_send(name)
end

#load(object, attributes) ⇒ self

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Load attribute

Parameters:

  • object (Object)
  • attributes (Hash)

Returns:

  • (self)


29
30
31
# File 'lib/anima/attribute.rb', line 29

def load(object, attributes)
  set(object, attributes.fetch(name))
end

#set(object, value) ⇒ self

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Set attribute value in object

Parameters:

  • object (Object)
  • value (Object)

Returns:

  • (self)


48
49
50
51
52
# File 'lib/anima/attribute.rb', line 48

def set(object, value)
  object.instance_variable_set(instance_variable_name, value)

  self
end