Sha256: 5c8e4a8d7f1d94690c589a921b1fe34baf0477674b4df67eef43170459e8d8d8

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

# rails generate effective:model NAME [field[:type] field[:type]] [options]

# Generates a model
# rails generate effective:model Thing
# rails generate effective:model Thing name:string description:text

module Effective
  module Generators
    class ModelGenerator < Rails::Generators::NamedBase
      include Helpers

      source_root File.expand_path(('../' * 4) + 'lib/scaffolds', __FILE__)

      desc 'Creates a model in your app/models folder.'

      argument :attributes, type: :array, default: [], banner: 'field[:type] field[:type]'

      def invoke_model
        say_status :invoke, :model, :white
      end

      def create_model
        template 'models/model.rb', File.join('app/models', class_path, "#{file_name}.rb")
      end

      protected

      def to_s_attribute
        attributes.find { |att| ['display_name', 'name', 'title', 'subject'].include?(att.name) }
      end

      def archived_attribute
        attributes.find { |att| att.name == 'archived' && att.type == :boolean }
      end

      def max_attribute_name_length
        @max_attribute_name_length ||= (attributes.map { |att| att.name.length }.max || 0)
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
effective_developer-0.0.10 lib/generators/effective/model_generator.rb
effective_developer-0.0.9 lib/generators/effective/model_generator.rb