Class: RailsExportRoutes::Formatters::JSONPretty
- Inherits:
-
Object
- Object
- RailsExportRoutes::Formatters::JSONPretty
- Defined in:
- lib/rails_export_routes/formatters/json_pretty.rb
Instance Method Summary collapse
-
#export_to_file(file) ⇒ Object
rubocop:disable Metrics/MethodLength.
-
#initialize(routes) ⇒ JSONPretty
constructor
A new instance of JSONPretty.
Constructor Details
#initialize(routes) ⇒ JSONPretty
Returns a new instance of JSONPretty.
8 9 10 |
# File 'lib/rails_export_routes/formatters/json_pretty.rb', line 8 def initialize(routes) @routes = routes end |
Instance Method Details
#export_to_file(file) ⇒ Object
rubocop:disable Metrics/MethodLength
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rails_export_routes/formatters/json_pretty.rb', line 12 def export_to_file(file) # rubocop:disable Metrics/MethodLength data = @routes.map do |route| { verb: route.verb, path: route.path_spec, controller: route.controller, action: route.action, name: route.name, constraints: route.constraints.to_h } end File.open(file, 'wb') do |f| f.write(::JSON.pretty_generate(data)) end end |