module - Ruby/Rails: How to temporarily define what scope to call methods -


i have module:

module liquidfilters   include actionview::helpers::assettaghelper    def stylesheet_tag(stylesheet_file_path)     stylesheet_link_tag stylesheet_file_path   end end 

and spec:

describe liquidfilters   describe "#stylesheet_tag"     "should return css file in html (media=screen) tag"       helper.stylesheet_tag("/path/css").should match(/<link href="\/path\/css\.css" media="screen" rel="stylesheet" type="text\/css"\s*\/>/)     end   end end 

but wrong number of arguments (2 1) error:

failures:   1) liquidfilters#stylesheet_tag should return css file in html (media=screen) tag      failure/error: helper.stylesheet_tag("/path/css").should match(/<link href="\/path\/css\.css" media="screen" rel="stylesheet" type="text\/css"\s*\/>/)      wrong number of arguments (2 1)      # ./app/filters/liquid_filters.rb:16:in `stylesheet_tag'      # ./spec/helpers/liquid_filters_spec.rb:13 

i can see problem @ stylesheet_link_tag stylesheet_file_path in liquidfilters module -- stylesheet_link_tag supposed call assettaghelper private method "stylesheet_tag", ends calling liquidfilter's stylesheet_tag method.

question

how force stylesheet_link_tag call assettaghelper's methods, , not liquidfilter's?

note: i'd keep method name stylesheet_tag.

you include assettaghelper module in helper class avoid method name override, this:

require 'singleton'  module liquidfilters   class helper     include singleton       include actionview::helpers::assettaghelper   end    def stylesheet_tag(stylesheet_file_path)     helper.instance.stylesheet_link_tag stylesheet_file_path   end end 

that way, stylesheet_tag method won't mixed assettaghelper's private method.

edit

based on feedback, guess closest then:

module liquidfilters   include actionview::helpers::assettaghelper    alias :old_stylesheet_tag :stylesheet_tag    def stylesheet_tag(stylesheet_file_path, options = nil)     if options       old_stylesheet_tag(stylesheet_file_path, options)     else       stylesheet_link_tag stylesheet_file_path     end    end  end 

you override private method, don't think there other alternative proxying calls.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -