Class: Welo::Link
Instance Attribute Summary collapse
-
#from ⇒ Object
The pointing resource.
-
#label ⇒ Object
The labeling for this link.
-
#local ⇒ Object
The locality for this link.
-
#to ⇒ Object
If the link is lazy and there is no value to @to, will evaluate the :to lazy_block and set to to this value.
Attributes included from CanBeLazy
Instance Method Summary collapse
-
#identify ⇒ Object
Gets the identifying scheme corresponding to this link.
-
#initialize(from, to = nil, params = {}, &blk) ⇒ Link
constructor
Creates a link to the pointed resource to, it must respond to :path.
-
#nesting ⇒ Object
Gets the nesting of the from resource of this link.
-
#to_absolute_path ⇒ Object
Returns an absolute version of the path.
- #to_local_path ⇒ Object
-
#to_relative_path ⇒ Object
Returns a relative version of the path.
-
#to_s ⇒ Object
Returns a string representation of this link (i.e., an path).
Methods included from CanBeLazy
Constructor Details
#initialize(from, to = nil, params = {}, &blk) ⇒ Link
Creates a link to the pointed resource to, it must respond to :path
37 38 39 40 41 42 43 44 |
# File 'lib/welo/core/link.rb', line 37 def initialize(from, to=nil, params={}, &blk) @from = from @to = to @lazy = params.has_key?(:lazy) ? params[:lazy] : true @label = params[:label] @local = params[:local] lazy_blocks[:to] = blk if block_given? end |
Instance Attribute Details
#from ⇒ Object
The pointing resource
24 25 26 |
# File 'lib/welo/core/link.rb', line 24 def from @from end |
#label ⇒ Object
The labeling for this link
30 31 32 |
# File 'lib/welo/core/link.rb', line 30 def label @label end |
#local ⇒ Object
The locality for this link
33 34 35 |
# File 'lib/welo/core/link.rb', line 33 def local @local end |
#to ⇒ Object
If the link is lazy and there is no value to @to, will evaluate the :to lazy_block and set to to this value. If the link is not lazy, will just return @to
27 28 29 |
# File 'lib/welo/core/link.rb', line 27 def to @to end |
Instance Method Details
#identify ⇒ Object
Gets the identifying scheme corresponding to this link. For now the identification scheme is written in the to resource. Later, we’ll try to be able to identify pointed resources with an identifying scheme local to the from resource.
66 67 68 69 70 71 72 |
# File 'lib/welo/core/link.rb', line 66 def identify identify = if nesting nesting.identifier_sym else :default end end |
#nesting ⇒ Object
Gets the nesting of the from resource of this link.
58 59 60 |
# File 'lib/welo/core/link.rb', line 58 def nesting @nesting ||= from.nesting(label) end |
#to_absolute_path ⇒ Object
Returns an absolute version of the path. Meaning that we use the default identifying scheme.
76 77 78 |
# File 'lib/welo/core/link.rb', line 76 def to_absolute_path File.join('', to.path(:default).to_s) end |
#to_local_path ⇒ Object
88 89 90 |
# File 'lib/welo/core/link.rb', line 88 def to_local_path File.join('.', from.epithet_path_to(to, label).to_s) end |
#to_relative_path ⇒ Object
Returns a relative version of the path. We can use a different identification scheme of the pointed resource. Later, we’ll try to be able to identify pointed resources with a identifying scheme local to the from resource.
84 85 86 |
# File 'lib/welo/core/link.rb', line 84 def to_relative_path File.join('.', to.path(identify).to_s) end |
#to_s ⇒ Object
Returns a string representation of this link (i.e., an path)
94 95 96 97 98 99 100 101 102 |
# File 'lib/welo/core/link.rb', line 94 def to_s if nesting to_relative_path elsif local to_local_path else to_absolute_path end end |