Class: RouteGuard::Models::Route
- Inherits:
-
Object
- Object
- RouteGuard::Models::Route
- Defined in:
- lib/route_guard/models/route.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#constraints ⇒ Object
readonly
Returns the value of attribute constraints.
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
-
#defaults ⇒ Object
readonly
Returns the value of attribute defaults.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#original_path ⇒ Object
readonly
Returns the value of attribute original_path.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#verb ⇒ Object
readonly
Returns the value of attribute verb.
Instance Method Summary collapse
-
#initialize(verb:, path:, original_path:, controller:, action:, name: nil, constraints: {}, file: nil, line: nil, defaults: {}) ⇒ Route
constructor
A new instance of Route.
- #internal? ⇒ Boolean
- #location ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(verb:, path:, original_path:, controller:, action:, name: nil, constraints: {}, file: nil, line: nil, defaults: {}) ⇒ Route
Returns a new instance of Route.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/route_guard/models/route.rb', line 8 def initialize(verb:, path:, original_path:, controller:, action:, name: nil, constraints: {}, file: nil, line: nil, defaults: {}) @verb = verb.to_s.upcase @original_path = original_path.to_s @path = path.to_s @controller = controller&.to_s @action = action&.to_s @name = name&.to_s @constraints = constraints || {} @file = file @line = line ? line.to_i : nil @defaults = defaults || {} end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
6 7 8 |
# File 'lib/route_guard/models/route.rb', line 6 def action @action end |
#constraints ⇒ Object (readonly)
Returns the value of attribute constraints.
6 7 8 |
# File 'lib/route_guard/models/route.rb', line 6 def constraints @constraints end |
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
6 7 8 |
# File 'lib/route_guard/models/route.rb', line 6 def controller @controller end |
#defaults ⇒ Object (readonly)
Returns the value of attribute defaults.
6 7 8 |
# File 'lib/route_guard/models/route.rb', line 6 def defaults @defaults end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
6 7 8 |
# File 'lib/route_guard/models/route.rb', line 6 def file @file end |
#line ⇒ Object (readonly)
Returns the value of attribute line.
6 7 8 |
# File 'lib/route_guard/models/route.rb', line 6 def line @line end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/route_guard/models/route.rb', line 6 def name @name end |
#original_path ⇒ Object (readonly)
Returns the value of attribute original_path.
6 7 8 |
# File 'lib/route_guard/models/route.rb', line 6 def original_path @original_path end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/route_guard/models/route.rb', line 6 def path @path end |
#verb ⇒ Object (readonly)
Returns the value of attribute verb.
6 7 8 |
# File 'lib/route_guard/models/route.rb', line 6 def verb @verb end |
Instance Method Details
#internal? ⇒ Boolean
21 22 23 |
# File 'lib/route_guard/models/route.rb', line 21 def internal? controller.to_s.start_with?("rails/") || path.start_with?("/rails/") || path == "/assets" end |
#location ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/route_guard/models/route.rb', line 25 def location if file && line # Try to make path relative to pwd for better readability relative_file = file.sub(/\A#{Regexp.escape(Dir.pwd)}\//, "") "#{relative_file}:#{line}" elsif file file.sub(/\A#{Regexp.escape(Dir.pwd)}\//, "") else "unknown location" end end |
#to_s ⇒ Object
37 38 39 |
# File 'lib/route_guard/models/route.rb', line 37 def to_s "#{verb} #{path}" end |