Class: Rails::Routes::Prettier::Objects::Route
- Inherits:
-
Object
- Object
- Rails::Routes::Prettier::Objects::Route
- Defined in:
- lib/rails/routes/prettier/objects/route.rb
Instance Attribute Summary collapse
-
#route ⇒ Object
readonly
Returns the value of attribute route.
Instance Method Summary collapse
- #action ⇒ Object
- #basic_auth? ⇒ Boolean
- #controller ⇒ Object
- #custom_router? ⇒ Boolean
-
#initialize(route) ⇒ Route
constructor
A new instance of Route.
-
#inspect ⇒ Object
rubocop:enable Layout/LineLength.
- #name ⇒ Object
- #path ⇒ Object
- #redirect? ⇒ Boolean
-
#req_options ⇒ Object
rubocop:disable Security/Eval.
- #reqs ⇒ Object
-
#to_h ⇒ Object
rubocop:enable Security/Eval.
- #to_json(*_args) ⇒ Object
-
#to_s ⇒ Object
rubocop:disable Layout/LineLength.
- #verb ⇒ Object
Constructor Details
#initialize(route) ⇒ Route
Returns a new instance of Route.
10 11 12 |
# File 'lib/rails/routes/prettier/objects/route.rb', line 10 def initialize(route) @route = route end |
Instance Attribute Details
#route ⇒ Object (readonly)
Returns the value of attribute route.
8 9 10 |
# File 'lib/rails/routes/prettier/objects/route.rb', line 8 def route @route end |
Instance Method Details
#action ⇒ Object
36 37 38 39 40 |
# File 'lib/rails/routes/prettier/objects/route.rb', line 36 def action return nil if redirect? || custom_router? || basic_auth? reqs.split('#').last.split(' ').first end |
#basic_auth? ⇒ Boolean
83 84 85 |
# File 'lib/rails/routes/prettier/objects/route.rb', line 83 def basic_auth? reqs.start_with?('#<Rack::Auth::Basic') end |
#controller ⇒ Object
30 31 32 33 34 |
# File 'lib/rails/routes/prettier/objects/route.rb', line 30 def controller return nil if redirect? || custom_router? || basic_auth? reqs.split('#').first.split('/').map(&:camelize).join('::').concat('Controller') end |
#custom_router? ⇒ Boolean
87 88 89 |
# File 'lib/rails/routes/prettier/objects/route.rb', line 87 def custom_router? reqs.start_with?('#<') end |
#inspect ⇒ Object
rubocop:enable Layout/LineLength
75 76 77 |
# File 'lib/rails/routes/prettier/objects/route.rb', line 75 def inspect "##{self}" end |
#name ⇒ Object
14 15 16 |
# File 'lib/rails/routes/prettier/objects/route.rb', line 14 def name route[:name] end |
#path ⇒ Object
22 23 24 |
# File 'lib/rails/routes/prettier/objects/route.rb', line 22 def path route[:path].gsub(/(\(\.:format\))$/, '') end |
#redirect? ⇒ Boolean
79 80 81 |
# File 'lib/rails/routes/prettier/objects/route.rb', line 79 def redirect? reqs.match?(/redirect(.*,|.*$)/) end |
#req_options ⇒ Object
rubocop:disable Security/Eval
43 44 45 46 47 48 49 50 51 |
# File 'lib/rails/routes/prettier/objects/route.rb', line 43 def return {} if redirect? || basic_auth? begin eval(reqs.split("#{action} ").last) rescue StandardError {} end end |
#reqs ⇒ Object
26 27 28 |
# File 'lib/rails/routes/prettier/objects/route.rb', line 26 def reqs route[:reqs] end |
#to_h ⇒ Object
rubocop:enable Security/Eval
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rails/routes/prettier/objects/route.rb', line 54 def to_h { name: name, verb: verb, path: path, controller: controller, action: action, req_options: } end |
#to_json(*_args) ⇒ Object
65 66 67 |
# File 'lib/rails/routes/prettier/objects/route.rb', line 65 def to_json(*_args) to_h.to_json end |
#to_s ⇒ Object
rubocop:disable Layout/LineLength
70 71 72 |
# File 'lib/rails/routes/prettier/objects/route.rb', line 70 def to_s "<Route name: '#{name}', verb: '#{verb}', path: '#{path}', controller: '#{controller}', action: '#{action}' req_options: #{}>" end |
#verb ⇒ Object
18 19 20 |
# File 'lib/rails/routes/prettier/objects/route.rb', line 18 def verb route[:verb] end |