Class: Anima

Inherits:
Module
  • Object
show all
Includes:
Adamantium::Flat
Defined in:
lib/anima.rb,
lib/anima/error.rb,
lib/anima/update.rb,
lib/anima/builder.rb,
lib/anima/attribute.rb

Overview

Main library namespace and mixin

Defined Under Namespace

Modules: Update Classes: Attribute, Builder, 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



25
26
27
# File 'lib/anima.rb', line 25

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)


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

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, :bar)
anima.add(:foo) # equals Anima.new(:foo, :bar)

Returns:



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

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>)


77
78
79
# File 'lib/anima.rb', line 77

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)


65
66
67
68
69
# File 'lib/anima.rb', line 65

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)


92
93
94
95
96
97
98
# File 'lib/anima.rb', line 92

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

#remove(*names) ⇒ Anima

Return new anima with attributes removed

Examples:

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

Returns:



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

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