Class: DynamicImage::Generators::ResourceGenerator

Inherits:
Rails::Generators::ResourceGenerator
  • Object
show all
Defined in:
lib/rails/generators/dynamic_image/resource/resource_generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(args, *options) ⇒ ResourceGenerator


11
12
13
# File 'lib/rails/generators/dynamic_image/resource/resource_generator.rb', line 11

def initialize(args, *options)
  super(inject_dynamic_image_attributes(args), *options)
end

Instance Method Details

#add_controller_extensionObject


15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rails/generators/dynamic_image/resource/resource_generator.rb', line 15

def add_controller_extension
  inject_into_file(
    File.join("app/controllers",
              class_path,
              "#{file_name.pluralize}_controller.rb"),
    after: "ApplicationController\n"
  ) do
    "  include DynamicImage::Controller\n\n  private\n\n" \
      "  def model\n    #{class_name}\n  end\n"
  end
end

#add_model_extensionObject


27
28
29
30
31
32
33
34
# File 'lib/rails/generators/dynamic_image/resource/resource_generator.rb', line 27

def add_model_extension
  inject_into_file(
    File.join("app/models", class_path, "#{file_name}.rb"),
    after: "ActiveRecord::Base\n"
  ) do
    "  include DynamicImage::Model\n"
  end
end

#alter_resource_routesObject


36
37
38
39
40
41
42
# File 'lib/rails/generators/dynamic_image/resource/resource_generator.rb', line 36

def alter_resource_routes
  gsub_file(
    File.join("config", "routes.rb"),
    " resources :#{file_name.pluralize}",
    " image_resources :#{file_name.pluralize}"
  )
end