Class: Anima Private

Inherits:
Module
  • Object
show all
Includes:
Adamantium::Flat
Defined in:
lib/anima.rb,
lib/anima/error.rb,
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.

Main library namespace and mixin

Defined Under Namespace

Modules: InstanceMethods Classes: Attribute, Error

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*names) ⇒ undefined

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 object



18
19
20
# File 'lib/anima.rb', line 18

def initialize(*names)
  @attributes = names.uniq.map(&Attribute.method(:new)).freeze
end

Instance Attribute Details

#attributesAttributeSet (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 names

Returns:

  • (AttributeSet)


13
14
15
# File 'lib/anima.rb', line 13

def attributes
  @attributes
end

Instance Method Details

#add(*names) ⇒ Anima

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 new anima with attributes added

Examples:

anima = Anima.new(:foo)
anima.add(:bar) # equals Anima.new(:foo, :bar)

Returns:



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

def add(*names)
  new(attribute_names + names)
end

#attribute_namesEnumerable<Symbol>

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 names

Returns:

  • (Enumerable<Symbol>)


60
61
62
# File 'lib/anima.rb', line 60

def attribute_names
  attributes.map(&:name)
end

#attributes_hash(object) ⇒ Hash

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 attributes hash for instance

Parameters:

  • object (Object)

Returns:

  • (Hash)


51
52
53
54
55
# File 'lib/anima.rb', line 51

def attributes_hash(object)
  attributes.each_with_object({}) do |attribute, attributes_hash|
    attributes_hash[attribute.name] = attribute.get(object)
  end
end

#initialize_instance(object, attribute_hash) ⇒ 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.

Initialize instance

Parameters:

  • object (Object)
  • attribute_hash (Hash)

Returns:

  • (self)


72
73
74
75
76
77
78
# File 'lib/anima.rb', line 72

def initialize_instance(object, attribute_hash)
  assert_known_attributes(object.class, attribute_hash)
  attributes.each do |attribute|
    attribute.load(object, attribute_hash)
  end
  self
end

#remove(*names) ⇒ Anima

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 new anima with attributes removed

Examples:

anima = Anima.new(:foo, :bar)
anima.remove(:bar) # equals Anima.new(:foo)

Returns:



42
43
44
# File 'lib/anima.rb', line 42

def remove(*names)
  new(attribute_names - names)
end