Sha256: 1f7fe9d099321e4cae69902588e5c4cc314ea14de979f85e2f2ac7a02068a732

Contents?: true

Size: 1009 Bytes

Versions: 1

Compression:

Stored size: 1009 Bytes

Contents

module ActivityEngine
  module Generators
    class RegisterGenerator < Rails::Generators::Base
      source_root File.expand_path("../templates", __FILE__)

      desc "Creates a ActivityEngine initializer."
      argument :class_name, type: :string
      argument :method_name, type: :string
      argument :subject_method, type: :string

      def copy_initializer
        generate('activity_engine:install')
        text = [
          "ActivityEngine.register('#{class_name}', '#{method_name}') do |activity, context|",
          "  activity.subject = context.#{subject_method}",
          "  activity.current_user = context.current_user",
          "  activity.activity_type = '#{class_name}##{method_name}'",
          "#  activity.message = 'Specify a custom message if applicable'",
          "end",
          "",
          ""
        ].join("\n")

        inject_into_file('config/post_initializers/activity_engine_config.rb', text, before: /\A.*ActivityEngine.register/)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activity_engine-0.0.7 lib/generators/activity_engine/register_generator.rb