Sha256: a5d2a0f461b66a715da491cffe569f8524ac9cc790acb3af700aa97f8cf511aa

Contents?: true

Size: 1.17 KB

Versions: 2

Compression:

Stored size: 1.17 KB

Contents

require 'rails/generators'

module Hancock::Gallery::Models
  class ImageGenerator < Rails::Generators::Base
    source_root File.expand_path('../templates', __FILE__)
    argument :class_name_arg, type: :string, default: ""
    argument :gallery_class_name_arg, type: :string, default: ""

    desc 'Hancock::Gallery Image Model generator'
    def image
      template 'image.erb', "app/models/#{file_name}.rb"
    end

    private
    def class_name
      class_name_arg.blank? ? "SetClassForImage" : class_name_arg
    end

    def capitalized_class_name
      class_name.capitalize
    end

    def camelcased_class_name
      class_name.camelcase
    end

    def file_name
      underscored_class_name
    end

    def underscored_class_name
      camelcased_class_name.underscore
    end

    def underscored_pluralized_class_name
      underscored_class_name.pluralize
    end

    def camelcased_gallery_class_name
      gallery_class_name.camelcase
    end

    def underscored_gallery_class_name
      gallery_class_name.underscore
    end

    def gallery_class_name
      gallery_class_name_arg.blank? ? camelcased_class_name.sub(/Image$/i, "") : gallery_class_name_arg
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hancock_cms_gallery-1.0.2 lib/generators/hancock/gallery/models/image_generator.rb
hancock_cms_gallery-1.0.0 lib/generators/hancock/gallery/models/image_generator.rb