Class: ActiveElement::Route
- Inherits:
-
Object
- Object
- ActiveElement::Route
- 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
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(controller:, required_permissions:, user_permissions:, action:, rails_component:) ⇒ Route
constructor
A new instance of Route.
- #path ⇒ Object
- #permissions ⇒ Object
- #permitted? ⇒ Boolean
- #primary? ⇒ Boolean
- #rails_route? ⇒ Boolean
- #spec ⇒ Object
- #title ⇒ Object
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 = @user_permissions = @action = action @rails_component = rails_component end |
Instance Attribute Details
#controller ⇒ Object (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 |
#path ⇒ Object
32 33 34 |
# File 'lib/active_element/route.rb', line 32 def path @path ||= rails_path end |
#permissions ⇒ Object
52 53 54 |
# File 'lib/active_element/route.rb', line 52 def .applicable.map { || .fetch(:with).to_s } end |
#permitted? ⇒ 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
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
56 57 58 |
# File 'lib/active_element/route.rb', line 56 def rails_route? rails_application_route? || active_element_route? end |
#spec ⇒ Object
48 49 50 |
# File 'lib/active_element/route.rb', line 48 def spec { controller: controller.controller_path, action: action.to_s } end |
#title ⇒ Object
44 45 46 |
# File 'lib/active_element/route.rb', line 44 def title controller.controller_name.titleize end |