Class: JSRailsRoutes::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/js_rails_routes/generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(builder, writable: File) ⇒ Generator

Returns a new instance of Generator.

Parameters:



10
11
12
13
# File 'lib/js_rails_routes/generator.rb', line 10

def initialize(builder, writable: File)
  @builder = builder
  @writable = writable
end

Instance Method Details

#generate(task) ⇒ Hash{String => String}

Parameters:

  • task (String)

Returns:

  • (Hash{String => String})


17
18
19
20
21
22
23
24
25
26
27
# File 'lib/js_rails_routes/generator.rb', line 17

def generate(task)
  builder.build.each do |artifact|
    file_name = File.join(config.output_dir, artifact.file_name)
    file_body = <<~FILE_BODY.chomp
      /* eslint-disable */
      // Don't edit manually. `rake #{task}` generates this file.
      #{artifact.body}
    FILE_BODY
    writable.write(file_name, file_body)
  end
end