Sha256: 3c4a7e18f483a799342dafd480ae70142128a9b139b7b2b012d7560b855f69ae

Contents?: true

Size: 944 Bytes

Versions: 4

Compression:

Stored size: 944 Bytes

Contents

require 'rails/generators/named_base'
require 'rails/generators/resource_helpers'

module Rails
  module Generators
    class JbGenerator < NamedBase # :nodoc:
      include Rails::Generators::ResourceHelpers

      source_root File.expand_path('../templates', __FILE__)

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

      def create_root_folder
        path = File.join('app/views', controller_file_path)
        empty_directory path unless File.directory?(path)
      end

      def copy_view_files
        template 'index.json.jb', File.join('app/views', controller_file_path, 'index.json.jb')
        template 'show.json.jb', File.join('app/views', controller_file_path, 'show.json.jb')
      end


      private
      def attributes_names
        [:id] + super
      end

      def attributes_names_with_timestamps
        attributes_names + %w(created_at updated_at)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jb-0.4.1 lib/generators/rails/jb_generator.rb
jb-0.4.0 lib/generators/rails/jb_generator.rb
jb-0.3.0 lib/generators/rails/jb_generator.rb
jb-0.2.0 lib/generators/rails/jb_generator.rb