Class: Linkificator::ConditionsStorage::Condition

Inherits:
Object
  • Object
show all
Defined in:
lib/linkificator/conditions_storage/condition.rb

Defined Under Namespace

Classes: ViewContext

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Condition

Returns a new instance of Condition.



4
5
6
# File 'lib/linkificator/conditions_storage/condition.rb', line 4

def initialize(options={})
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



2
3
4
# File 'lib/linkificator/conditions_storage/condition.rb', line 2

def options
  @options
end

Instance Method Details



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/linkificator/conditions_storage/condition.rb', line 17

def link_to(name = nil, options = nil, html_options = nil, &block)
  html_options, options, name = options, name, block if block_given?
  options ||= {}

  view_context = view_context((html_options || {}).delete(:view_context))

  if processing[:data_href]
    url          = view_context.url_for(*options)
    html_options = (html_options || {}).merge('href' => '#', 'data-href' => Base64.strict_encode64(url))
  end

  if processing[:rel_nofollow]
    html_options = (html_options || {}).merge(rel: 'nofollow')
  end


  link = if block_given?
           call_link_method(view_context, options, html_options, &block)
         else
           call_link_method(view_context, name, options, html_options)
         end

  if processing[:wrap_noindex]
    view_context.(:noindex) { link }
  else
    link
  end
end

#match?(options) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
11
12
13
14
15
# File 'lib/linkificator/conditions_storage/condition.rb', line 8

def match?(options)
  [
      context[:target]      ?  detect_presence(context[:target],      options[:target])  : true,
      context[:target_not]  ? !detect_presence(context[:target_not],  options[:target])  : true,
      context[:current]     ?  detect_presence(context[:current],     options[:current]) : true,
      context[:current_not] ? !detect_presence(context[:current_not], options[:current]) : true,
  ].all?
end