module Pouch
Constants
- VERSION
Public Class Methods
included(base)
click to toggle source
# File lib/pouch.rb, line 12 def self.included base base.extend self end
new(browser, start = false, opts = {})
click to toggle source
# File lib/pouch.rb, line 16 def initialize browser, start = false, opts = {} if start.is_a?(Hash) && opts.empty? opts = start start = false end @browser = browser @context = standardize opts[:context] if opts[:context] @timeout = opts[:timeout] || 5 set_timer if self.respond_to? :set_timer visit if self.respond_to?(:visit) && start contextualize_methods end
Public Instance Methods
browser()
click to toggle source
# File lib/pouch.rb, line 32 def browser @browser end
context()
click to toggle source
# File lib/pouch.rb, line 36 def context @context end
page_url=(str)
click to toggle source
# File lib/pouch.rb, line 44 def page_url= str define_method :visit do self.browser.goto str end end
timeout()
click to toggle source
# File lib/pouch.rb, line 40 def timeout @timeout end
Private Instance Methods
contextualize_methods()
click to toggle source
# File lib/pouch.rb, line 52 def contextualize_methods return unless context context.each_with_object([]) do |ctxt, array| next unless array.flatten.empty? array << match_and_replace(ctxt) end end
get_match(context)
click to toggle source
# File lib/pouch.rb, line 64 def get_match context methods.select{ |mthd| mthd.to_s.start_with? "#{context}_" }.each_with_object([]) do |mthd, array| unless respond_to? mthd.to_s.gsub("#{context}_", "") raise ReplacementError, "#{self.class} defined no standard method for replacement '#{mthd}'" end array << mthd end end
match_and_replace(context)
click to toggle source
# File lib/pouch.rb, line 60 def match_and_replace context get_match(context).map{ |mthd| self.method mthd }.each{ |mthd| replace_method mthd, context } end
replace_method(method, context)
click to toggle source
# File lib/pouch.rb, line 73 def replace_method method, context (class << self; self; end).class_eval{ define_method method.name.to_s.gsub("#{context}_",""), method } end
standardize(context)
click to toggle source
# File lib/pouch.rb, line 77 def standardize context context.map!{ |c| standardize c } if context.kind_of? Array if [Array, String, Symbol].include? context.class [context].flatten.map(&:to_s) else raise ContextArgumentError, "cannot define Pouch context with #{context.class}" end end