Class: Relevance::Tarantula::Link

Inherits:
Object
  • Object
show all
Extended by:
ActionView::Helpers::UrlHelper
Defined in:
lib/relevance/tarantula/link.rb

Constant Summary collapse

METHOD_REGEXPS =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(link) ⇒ Link

Returns a new instance of Link.



22
23
24
25
26
27
28
29
30
# File 'lib/relevance/tarantula/link.rb', line 22

def initialize(link)
  if String === link || link.nil?
    @href = link
    @method = :get
  else # should be a tag
    @href = link['href'].downcase
    @tag = link
  end
end

Instance Attribute Details

#hrefObject

Returns the value of attribute href.



20
21
22
# File 'lib/relevance/tarantula/link.rb', line 20

def href
  @href
end

Class Method Details

.protect_against_forgery?Boolean

method_javascript_function needs this method

Returns:

  • (Boolean)


6
7
8
# File 'lib/relevance/tarantula/link.rb', line 6

def protect_against_forgery?
  false
end

Instance Method Details

#==(obj) ⇒ Object Also known as: eql?



42
43
44
45
# File 'lib/relevance/tarantula/link.rb', line 42

def ==(obj)
  obj.respond_to?(:href) && obj.respond_to?(:method) &&
    self.href.to_s == obj.href.to_s && self.method.to_s == obj.method.to_s
end

#hashObject



48
49
50
# File 'lib/relevance/tarantula/link.rb', line 48

def hash
  to_s.hash
end

#methodObject



32
33
34
35
36
37
38
39
40
# File 'lib/relevance/tarantula/link.rb', line 32

def method
  @method ||= begin
    (@tag &&
     [:put, :delete, :post].detect do |m| # post should be last since it's least specific
       @tag['onclick'] =~ METHOD_REGEXPS[m]
     end) ||
    :get
  end
end

#to_sObject



52
53
54
# File 'lib/relevance/tarantula/link.rb', line 52

def to_s
  "<Relevance::Tarantula::Link href=#{href}, method=#{method}>"
end