Class: ActiveRecord::Generators::RubyGalleryGenerator

Inherits:
Base
  • Object
show all
Includes:
RubyGallery::Generators::OrmHelpers
Defined in:
lib/generators/active_record/ruby_gallery_generator.rb

Instance Method Summary collapse

Methods included from RubyGallery::Generators::OrmHelpers

#controller_exists?, #controller_path, #migration_add_columns_exists?, #migration_exists?, #migration_path, #model_contents, #model_exists?, #model_path

Instance Method Details



11
12
13
14
15
16
17
18
19
20
# File 'lib/generators/active_record/ruby_gallery_generator.rb', line 11

def copy_ruby_gallery_migration
  route "put '/#{table_name}/update_ruby_gallery_position', controller: :#{table_name}, action: :update_ruby_gallery_position"
  route "post '/#{table_name}/upload_album', controller: :#{table_name}, action: :upload_album"
  route "delete '/#{table_name}/:id/delete_photo', controller: :#{table_name}, action: :delete_photo"
  if migration_exists?("album_photos") && migration_add_columns_exists?("album_photos")
  else
    migration_template "album_photo_migration.rb", "db/migrate/ruby_gallery_create_album_photos"
    migration_template "migration.rb", "db/migrate/ruby_gallery_add_columns_to_album_photos"
  end
end


30
31
32
33
34
35
36
37
# File 'lib/generators/active_record/ruby_gallery_generator.rb', line 30

def inject_ruby_gallery_content_to_controller
  content = %Q{  upload_album_for :#{table_name}}

  class_path = class_name.to_s.split("::")
  indent_depth = class_path.size - 1
  content = content.split("\n").map { |line| "  " * indent_depth + line } .join("\n") << "\n"
  inject_into_class(controller_path, class_path.last.tableize.camelize + "Controller", content) if controller_exists?
end


22
23
24
25
26
27
28
# File 'lib/generators/active_record/ruby_gallery_generator.rb', line 22

def inject_ruby_gallery_content_to_model
  content = %Q{  has_many :album_photos, as: :photoable}
  class_path = class_name.to_s.split("::")
  indent_depth = class_path.size - 1
  content = content.split("\n").map { |line| "  " * indent_depth + line } .join("\n") << "\n"
  inject_into_class(model_path, class_path.last, content) if model_exists?
end