Class: Vedeu::Repositories::Collection Private

Inherits:
Object
  • Object
show all
Includes:
Common, Assemblage
Defined in:
lib/vedeu/repositories/collection.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.

Convert an Array into an object which has some meaning in the context it is being used. Various classes throughout Vedeu subclass this class.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Assemblage

#[], #any?, #each, #empty?, #eql?, #size

Methods included from Common

#absent?, #array?, #boolean, #boolean?, #empty_value?, #escape?, #falsy?, #hash?, #line_model?, #numeric?, #positionable?, #present?, #snake_case, #stream_model?, #string?, #symbol?, #truthy?, #view_model?

Constructor Details

#initialize(collection = [], parent = nil, name = nil) ⇒ Vedeu::Repositories::Collection

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.

Returns a new instance of Vedeu::Repositories::Collection.

Parameters:

  • collection (void) (defaults to: [])
  • parent (void) (defaults to: nil)
  • name (NilClass|Symbol|String) (defaults to: nil)

    The name of the model or target model to act upon. May default to ‘Vedeu.focus`.



52
53
54
55
56
# File 'lib/vedeu/repositories/collection.rb', line 52

def initialize(collection = [], parent = nil, name = nil)
  @collection = collection
  @parent     = parent
  @name       = name
end

Instance Attribute Details

#collectionArray|Vedeu::Repositories::Collection (readonly) Also known as: all, value

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.



20
21
22
# File 'lib/vedeu/repositories/collection.rb', line 20

def collection
  @collection
end

#nameString|Symbol|NilClass

Returns:

  • (String|Symbol|NilClass)


30
31
32
# File 'lib/vedeu/repositories/collection.rb', line 30

def name
  @name
end

#parentFixnum

Returns:

  • (Fixnum)


26
27
28
# File 'lib/vedeu/repositories/collection.rb', line 26

def parent
  @parent
end

Class Method Details

.coerce(collection = [], parent = nil, name = nil) ⇒ Vedeu::Repositories::Collection

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.

Parameters:

  • collection (Array|Vedeu::Repositories::Collection) (defaults to: [])
  • parent (void) (defaults to: nil)
  • name (NilClass|Symbol|String) (defaults to: nil)

    The name of the model or target model to act upon. May default to ‘Vedeu.focus`.

Returns:



36
37
38
39
40
41
42
43
44
# File 'lib/vedeu/repositories/collection.rb', line 36

def self.coerce(collection = [], parent = nil, name = nil)
  if collection.is_a?(Vedeu::Repositories::Collection)
    collection

  else
    new(Array(collection), parent, name)

  end
end

Instance Method Details

#add(other) ⇒ Vedeu::Repositories::Collection Also known as: <<

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.

Adds an entry to the collection.



62
63
64
65
66
67
68
69
70
# File 'lib/vedeu/repositories/collection.rb', line 62

def add(other)
  if other.is_a?(Vedeu::Repositories::Collection)
    return klass.coerce(other, parent, name) if empty?

  else
    klass.new(@collection += Array(other), parent, name)

  end
end

#klassvoid (private)

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.

This method returns an undefined value.

Return the inheriting class.



86
87
88
# File 'lib/vedeu/repositories/collection.rb', line 86

def klass
  self.class
end

#to_sString Also known as: to_str

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.

Returns the collection as a String.

Returns:

  • (String)


76
77
78
# File 'lib/vedeu/repositories/collection.rb', line 76

def to_s
  collection.map(&:to_s).join
end