Class: Navigatrix::Item::State

Inherits:
OpenStruct
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/navigatrix/item.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, context) ⇒ State

Returns a new instance of State.



79
80
81
82
# File 'lib/navigatrix/item.rb', line 79

def initialize(config, context)
  @context = context
  super(config)
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



77
78
79
# File 'lib/navigatrix/item.rb', line 77

def context
  @context
end

Instance Method Details

#action_matches?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/navigatrix/item.rb', line 92

def action_matches?
  actions.empty? || actions.include?(action_name)
end

#actionsObject



104
105
106
# File 'lib/navigatrix/item.rb', line 104

def actions
  Array.wrap(super)
end

#applicable?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/navigatrix/item.rb', line 84

def applicable?
  path ? path_matches? : (controller_matches? && action_matches?)
end

#controller_matches?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/navigatrix/item.rb', line 88

def controller_matches?
  match?(controller, controller_name)
end

#match?(pattern, target) ⇒ Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/navigatrix/item.rb', line 100

def match?(pattern, target)
  pattern.is_a?(Regexp) ? target[pattern] : pattern == target
end

#path_matches?Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/navigatrix/item.rb', line 96

def path_matches?
  match?(path, current_path)
end