Class: Correlate::Links

Inherits:
Object
  • Object
show all
Defined in:
lib/correlate/links.rb

Overview

Thin proxy around the array of links.

Instance Method Summary collapse

Constructor Details

#initialize(klass, array = []) ⇒ Links

Returns a new instance of Links.



7
8
9
10
# File 'lib/correlate/links.rb', line 7

def initialize( klass, array = [] )
  @klass = klass
  @target_array = array
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (protected)



85
86
87
# File 'lib/correlate/links.rb', line 85

def method_missing( name, *args, &block )
  @target_array.send( name, *args, &block )
end

Instance Method Details

#<<(obj) ⇒ Object Also known as: push, concat

Add an object to the list



21
22
23
# File 'lib/correlate/links.rb', line 21

def <<( obj )
  write_target.push({ 'rel' => rel_for_object( obj ), 'href' => id_for_object( obj ) })
end

#__debug__Object



42
43
44
45
46
47
48
49
50
# File 'lib/correlate/links.rb', line 42

def __debug__
  {
    :object_id => object_id,
    :klass => @klass,
    :target_array => @target_array,
    :original_copy => @original_copy,
    :original_copy_object_id => @original_copy.object_id
  }
end

#delete(obj) ⇒ Object

Delete this object from the list



36
37
38
39
40
# File 'lib/correlate/links.rb', line 36

def delete( obj )
  rel = rel_for_object( obj )

  write_target.reject! { |l| l['rel'] == rel }
end

#rel(rel) ⇒ Correlate::Links

Extract all the matching links for rel.

Parameters:

  • rel (String)

Returns:



16
17
18
# File 'lib/correlate/links.rb', line 16

def rel( rel )
  clone( @target_array.select { |link| link['rel'] == rel } )
end

#replace(obj) ⇒ Object

Replace a matching rel with this object



29
30
31
32
33
# File 'lib/correlate/links.rb', line 29

def replace( obj )
  delete( obj )

  self.<< obj
end