Sylar
Sylar

Reputation: 12092

Override ShopifyApp Module Method

I'm trying to override ShopifyApp's new method but not sure where to start. Basically I need to add another field to get a params:

/lib/shopify_app/sessions_concern/new.rb:

module ShopifyApp
  module SessionsConcern
    module New
      def new
        if params[:field] == "abc"
         authenticate if params[:shop].present?
        end # or else ...
      end
    end
  end
end

To use that module, I would do something like this in a controller:

ShopifyApp::SessionsConcern.prepend ShopifyApp::SessionsConcern::New

But there's no where to use that. How to go about this the correct way?

Upvotes: 0

Views: 220

Answers (1)

Andrey Deineko
Andrey Deineko

Reputation: 52367

Overriding is overriding. The following would do it for you without any prepending (having that you are loading the code from lib directory):

# lib/shopify_monkeypatching.rb
module ShopifyApp
  module SessionsConcern
    def new
      if params[:field] == "abc"
       authenticate if params[:shop].present?
      end # or else ...
    end
  end
end

Upvotes: 1

Related Questions