Sha256: 6ec3848ba3ebb971e6460ca069fd18ab81ec879f800c364d7ff36ebc3b7950fa

Contents?: true

Size: 896 Bytes

Versions: 1

Compression:

Stored size: 896 Bytes

Contents

require 'rails/generators'

module Transcript
  class InstallGenerator < Rails::Generators::NamedBase
    source_root File.expand_path('../templates', __FILE__)

    def generate_model
      invoke "active_record:model", [
        name,
        "action:string",
        "actor:references{polymorphic}",
        "receiver:references{polymorphic}",
        "receiver_serialized:jsonb",
        "meta:jsonb",
      ]
    end

    def generate_configuration_initializer
      template "transcript.rb.erb", "config/initializers/transcript.rb"
    end

    def add_model_concern
      inject_into_class "app/models/#{file_path}.rb",
        class_name,
        "  include Transcript::Model\n\n"
    end

    def add_controller_concern
      inject_into_class "app/controllers/application_controller.rb",
        "ApplicationController",
        "  include Transcript::Controller\n\n"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
transcript-0.3.0 lib/generators/transcript/install_generator.rb