Sha256: 6ccf181aea428f95da45c269bdec6a3ee8e84948ef2bbb9cf80824210af61b17

Contents?: true

Size: 1.09 KB

Versions: 5

Compression:

Stored size: 1.09 KB

Contents

module FileBlobs

class BlobOwnerGenerator < Rails::Generators::NamedBase
  source_root File.expand_path('../templates', __FILE__)

  check_class_collision

  class_option :attr_name, type: :string, default: 'file',
      desc: 'The name of the attribute pointing to the blob model'
  class_option :blob_model, type: :string, default: 'FileBlob',
      desc: 'The name of the model class that stores the file contents'
  class_option :allow_nil, type: :boolean, default: false,
      desc: "Support models that don't store files"

  def create_file_blob_model
    # Set up the template environment.
    template 'blob_owner.rb.erb', File.join('app', 'models', "#{file_name}.rb")
    template 'blob_owner_test.rb.erb',
             File.join('test', 'models', "#{file_name}_test.rb")
    template '002_create_blob_owners.rb.erb',
        File.join('db', 'migrate',
                  "20161029000002_create_#{file_name.tableize}.rb")
    template 'blob_owners.yml.erb',
             File.join('test', 'fixtures', "#{file_name.tableize}.yml")
  end
end  # class FileBlobs::BlobModelGenerator

end  # namespace FileBlobs

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
file_blobs_rails-0.2.3 lib/file_blobs_rails/generators/blob_owner_generator.rb
file_blobs_rails-0.2.2 lib/file_blobs_rails/generators/blob_owner_generator.rb
file_blobs_rails-0.2.1 lib/file_blobs_rails/generators/blob_owner_generator.rb
file_blobs_rails-0.2.0 lib/file_blobs_rails/generators/blob_owner_generator.rb
file_blobs_rails-0.1.0 lib/file_blobs_rails/generators/blob_owner_generator.rb