Sha256: 70f6d97db6019a9baea96f03e25c5aa021d9a9e82eb778337a896203bc0024f4

Contents?: true

Size: 874 Bytes

Versions: 3

Compression:

Stored size: 874 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",
      ]
    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

3 entries across 3 versions & 1 rubygems

Version Path
transcript-0.2.1 lib/generators/transcript/install_generator.rb
transcript-0.2.0 lib/generators/transcript/install_generator.rb
transcript-0.1.0 lib/generators/transcript/install_generator.rb