Class: ActiveElement::Route

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/active_element/route.rb

Overview

Abstraction of a Rails route, includes path, permitted state (based on user permissions), etc.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller:, required_permissions:, user_permissions:, action:, rails_component:) ⇒ Route

Returns a new instance of Route.



10
11
12
13
14
15
16
# File 'lib/active_element/route.rb', line 10

def initialize(controller:, required_permissions:, user_permissions:, action:, rails_component:)
  @controller = controller
  @required_permissions = required_permissions
  @user_permissions = user_permissions
  @action = action
  @rails_component = rails_component
end

Instance Attribute Details

#controllerObject (readonly)

Returns the value of attribute controller.



8
9
10
# File 'lib/active_element/route.rb', line 8

def controller
  @controller
end

Instance Method Details

#<=>(other) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/active_element/route.rb', line 18

def <=>(other)
  return 0 if path.nil? && other.path.nil?
  return 1 if path.nil?
  return -1 if other.path.nil?

  path <=> other.path
end

#pathObject



32
33
34
# File 'lib/active_element/route.rb', line 32

def path
  @path ||= rails_path
end

#permissionsObject



52
53
54
# File 'lib/active_element/route.rb', line 52

def permissions
  permissions_check.applicable.map { |permission| permission.fetch(:with).to_s }
end

#permitted?Boolean

Returns:

  • (Boolean)


26
27
28
29
30
# File 'lib/active_element/route.rb', line 26

def permitted?
  return @permitted if defined?(@permitted)

  (@permitted = permitted_action?)
end

#primary?Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
42
# File 'lib/active_element/route.rb', line 36

def primary?
  return false if rails_non_index_action?
  return false unless resourceless_get_request?
  return false if excluded_ancestor?

  true
end

#rails_route?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/active_element/route.rb', line 56

def rails_route?
  rails_application_route? || active_element_route?
end

#specObject



48
49
50
# File 'lib/active_element/route.rb', line 48

def spec
  { controller: controller.controller_path, action: action.to_s }
end

#titleObject



44
45
46
# File 'lib/active_element/route.rb', line 44

def title
  controller.controller_name.titleize
end