Sha256: 4e0da2a63029f640e5b4d3f23121674df30e6f3977497d1e18f12233181782b6

Contents?: true

Size: 1.14 KB

Versions: 38

Compression:

Stored size: 1.14 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', resource.model_file
      end

      protected

      def parent_class_name
        options[:parent] || (Rails::VERSION::MAJOR > 4 ? 'ApplicationRecord' : 'ActiveRecord::Base')
      end

      def to_s_attribute
        [:display_name, :name, :title, :subject].find { |att| invoked_attributes.key?(att) }
      end

      def max_attribute_name_length
        @max_attribute_name_length ||= (invoked_attributes.keys.map { |att| att.to_s.length }.max || 0)
      end

    end
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
effective_developer-0.5.0 lib/generators/effective/model_generator.rb
effective_developer-0.4.16 lib/generators/effective/model_generator.rb
effective_developer-0.4.15 lib/generators/effective/model_generator.rb
effective_developer-0.4.14 lib/generators/effective/model_generator.rb
effective_developer-0.4.13 lib/generators/effective/model_generator.rb
effective_developer-0.4.12 lib/generators/effective/model_generator.rb
effective_developer-0.4.11 lib/generators/effective/model_generator.rb
effective_developer-0.4.10 lib/generators/effective/model_generator.rb
effective_developer-0.4.9 lib/generators/effective/model_generator.rb
effective_developer-0.4.8 lib/generators/effective/model_generator.rb
effective_developer-0.4.7 lib/generators/effective/model_generator.rb
effective_developer-0.4.6 lib/generators/effective/model_generator.rb
effective_developer-0.4.5 lib/generators/effective/model_generator.rb
effective_developer-0.4.4 lib/generators/effective/model_generator.rb
effective_developer-0.4.3 lib/generators/effective/model_generator.rb
effective_developer-0.4.2 lib/generators/effective/model_generator.rb
effective_developer-0.4.1 lib/generators/effective/model_generator.rb
effective_developer-0.4.0 lib/generators/effective/model_generator.rb