Sha256: ac346c8223e462d114d3f97f0a10e3a0ec64380b81ecc293de2a9b491ef16e49

Contents?: true

Size: 853 Bytes

Versions: 26

Compression:

Stored size: 853 Bytes

Contents

module Rails
  module Generators
    class DecanterGenerator < NamedBase
      source_root File.expand_path('../templates', __FILE__)
      check_class_collision :suffix => 'Decanter'
      ASSOCIATION_TYPES = [:has_many, :has_one, :belongs_to]

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

      class_option :parent, :type => :string, :desc => 'The parent class for the generated decanter'

      def create_decanter_file
        template 'decanter.rb.erb', File.join('app/decanters', class_path, "#{file_name}_decanter.rb")
      end

      private

      def inputs
        attributes.find_all { |attr| ASSOCIATION_TYPES.exclude?(attr.type) }
      end

      def associations
        attributes - inputs
      end

      def parent_class_name
        'Decanter::Base'
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
decanter-3.3.0 lib/generators/rails/decanter_generator.rb
decanter-3.2.1 lib/generators/rails/decanter_generator.rb
decanter-3.2.0 lib/generators/rails/decanter_generator.rb
decanter-3.1.2 lib/generators/rails/decanter_generator.rb
decanter-3.1.1 lib/generators/rails/decanter_generator.rb
decanter-3.1.0 lib/generators/rails/decanter_generator.rb
decanter-3.0.1 lib/generators/rails/decanter_generator.rb
decanter-3.0.0 lib/generators/rails/decanter_generator.rb
decanter-1.1.10 lib/generators/rails/decanter_generator.rb
decanter-1.1.8 lib/generators/rails/decanter_generator.rb
decanter-1.1.7 lib/generators/rails/decanter_generator.rb
decanter-1.1.6 lib/generators/rails/decanter_generator.rb
decanter-1.1.5 lib/generators/rails/decanter_generator.rb
decanter-1.1.4 lib/generators/rails/decanter_generator.rb
decanter-1.0.3 lib/generators/rails/decanter_generator.rb
decanter-1.0.2 lib/generators/rails/decanter_generator.rb
decanter-1.0.1 lib/generators/rails/decanter_generator.rb
decanter-0.9.2 lib/generators/rails/decanter_generator.rb
decanter-0.9.1 lib/generators/rails/decanter_generator.rb
decanter-0.9.0 lib/generators/rails/decanter_generator.rb