Sha256: 7baae59590f87db09748e630c4241cba8e524d4b0af5c4e8af2258ea721520b1

Contents?: true

Size: 1.3 KB

Versions: 25

Compression:

Stored size: 1.3 KB

Contents

require 'rails/generators/base'

module ShopifyApp
  module Generators
    class AddAfterAuthenticateJobGenerator < Rails::Generators::Base
      source_root File.expand_path('../templates', __FILE__)

      hook_for :test_framework, as: :job, in: :rails do |instance, generator|
        instance.invoke generator, [ instance.send(:job_file_name) ]
      end

      def init_after_authenticate_config
        initializer = load_initializer

        after_authenticate_job_config =
          "  config.after_authenticate_job = "\
          "{ job: \"Shopify::AfterAuthenticateJob\", inline: false }\n"

        inject_into_file(
          'config/initializers/shopify_app.rb',
          after_authenticate_job_config,
          before: 'end'
        )

        unless initializer.include?(after_authenticate_job_config)
          shell.say("Error adding after_authenticate_job to config. Add this line manually: #{after_authenticate_job_config}", :red)
        end
      end

      def add_after_authenticate_job
        template 'after_authenticate_job.rb', "app/jobs/#{job_file_name}_job.rb"
      end

      private

      def load_initializer
        File.read(File.join(destination_root, 'config/initializers/shopify_app.rb'))
      end

      def job_file_name
        'shopify/after_authenticate'
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
shopify_app-13.0.0 lib/generators/shopify_app/add_after_authenticate_job/add_after_authenticate_job_generator.rb
shopify_app-12.0.7 lib/generators/shopify_app/add_after_authenticate_job/add_after_authenticate_job_generator.rb
shopify_app-12.0.6 lib/generators/shopify_app/add_after_authenticate_job/add_after_authenticate_job_generator.rb
shopify_app-12.0.5 lib/generators/shopify_app/add_after_authenticate_job/add_after_authenticate_job_generator.rb
shopify_app-12.0.4 lib/generators/shopify_app/add_after_authenticate_job/add_after_authenticate_job_generator.rb
shopify_app-12.0.3 lib/generators/shopify_app/add_after_authenticate_job/add_after_authenticate_job_generator.rb
shopify_app-12.0.2 lib/generators/shopify_app/add_after_authenticate_job/add_after_authenticate_job_generator.rb
shopify_app-12.0.1 lib/generators/shopify_app/add_after_authenticate_job/add_after_authenticate_job_generator.rb
shopify_app-12.0.0 lib/generators/shopify_app/add_after_authenticate_job/add_after_authenticate_job_generator.rb
shopify_app-11.7.1 lib/generators/shopify_app/add_after_authenticate_job/add_after_authenticate_job_generator.rb
shopify_app-11.7.0 lib/generators/shopify_app/add_after_authenticate_job/add_after_authenticate_job_generator.rb
shopify_app-11.6.0 lib/generators/shopify_app/add_after_authenticate_job/add_after_authenticate_job_generator.rb
shopify_app-11.5.1 lib/generators/shopify_app/add_after_authenticate_job/add_after_authenticate_job_generator.rb
shopify_app-11.5.0 lib/generators/shopify_app/add_after_authenticate_job/add_after_authenticate_job_generator.rb
shopify_app-11.4.0 lib/generators/shopify_app/add_after_authenticate_job/add_after_authenticate_job_generator.rb
shopify_app-11.3.2 lib/generators/shopify_app/add_after_authenticate_job/add_after_authenticate_job_generator.rb
shopify_app-11.3.1 lib/generators/shopify_app/add_after_authenticate_job/add_after_authenticate_job_generator.rb
shopify_app-11.3.0 lib/generators/shopify_app/add_after_authenticate_job/add_after_authenticate_job_generator.rb
shopify_app-11.2.0 lib/generators/shopify_app/add_after_authenticate_job/add_after_authenticate_job_generator.rb
shopify_app-11.1.0 lib/generators/shopify_app/add_after_authenticate_job/add_after_authenticate_job_generator.rb