Sha256: 350eb07dbd78ea150fe662c8fc484506e8e357d2c251e0c3a945a05627b28161

Contents?: true

Size: 974 Bytes

Versions: 1

Compression:

Stored size: 974 Bytes

Contents

# frozen_string_literal: true
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

1 entries across 1 versions & 1 rubygems

Version Path
jb-0.5.0 lib/generators/rails/jb_generator.rb