Sha256: 8e2bae7bee3218fe0223f905b4c03321ea042dab8327cb070d06634e69a86a0b

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

require 'rails/generators/named_base'
require 'rails/generators/active_record'
require 'sofav/local'
require 'sofav/decorator'

module Sofav
  module Generators
    class SofavGenerator < Rails::Generators::NamedBase
      source_root File.expand_path('../templates', __FILE__)
      argument :attributes, type: :array, default: [], banner: "field:type field:type"
      include Sofav::Local
      include Sofav::Decorator

      def create_model
        @agruments = "#{file_name}"

        attributes.each do |a|
          @agruments += " #{a.name}:#{a.type}"
        end

        generate "model", @agruments
      end

      def create_controller
        generate "controller", "Admin::#{file_name} --skip-routes"
      end

      def create_kaminari
          generate "kaminari:views", "default --views-prefix admin"
      end

      def create_locales_activerecord
        @record = Array.new
        attributes.each do |a|
          @record << a.name
        end

        create_config_record(file_name, @record)
      end
      
      def create_locales_attribute_types
        create_config_attribute(file_name, attributes)
      end

      def create_model_decorator
        create_decorator(file_name, class_name, attributes)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sofav-0.2.0 lib/generators/sofav/sofav_generator.rb