Sha256: 56d10f5ce69fe2efa2163066c2dc6be2bd3677a9debc0a5fff4730d15f3c13e9

Contents?: true

Size: 1003 Bytes

Versions: 1

Compression:

Stored size: 1003 Bytes

Contents

require 'rails/generators'

module Hancock::Catalog::Models
  class CategoryGenerator < Rails::Generators::Base
    source_root File.expand_path('../templates', __FILE__)
    argument :class_name, type: :string
    argument :item_class_name_arg, type: :string, default: ""

    desc 'Hancock::Catalog Category Model generator'
    def category
      template 'category.erb', "app/models/#{file_name}.rb"
    end

    private
    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_item_class_name
      item_class_name.camelcase
    end

    def item_class_name
      item_class_name_arg.blank? ? camelcased_class_name.sub(/Category$/i, "") : item_class_name_arg
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hancock_cms_catalog-1.0.2 lib/generators/hancock/catalog/models/category_generator.rb