Object
# File lib/typhoeus/remote_method.rb, line 5
5: def initialize(options = {})
6: @http_method = options.delete(:method) || :get
7: @options = options
8: @base_uri = options.delete(:base_uri)
9: @path = options.delete(:path)
10: @on_success = options[:on_success]
11: @on_failure = options[:on_failure]
12: @cache_responses = options.delete(:cache_responses)
13: @memoize_responses = options.delete(:memoize_responses) || @cache_responses
14: @cache_ttl = @cache_responses == true ? 0 : @cache_responses
15: @keys = nil
16:
17: clear_cache
18: end
# File lib/typhoeus/remote_method.rb, line 40
40: def add_response_block(block, args, options)
41: @response_blocks[args_options_key(args, options)] << block
42: end
# File lib/typhoeus/remote_method.rb, line 36
36: def already_called?(args, options)
37: @called_methods.has_key? args_options_key(args, options)
38: end
# File lib/typhoeus/remote_method.rb, line 28
28: def args_options_key(args, options)
29: "#{args.to_s}+#{options.to_s}"
30: end
# File lib/typhoeus/remote_method.rb, line 75
75: def argument_names
76: return @keys if @keys
77: pattern, keys = compile(@path)
78: @keys = keys.collect {|k| k.to_sym}
79: end
# File lib/typhoeus/remote_method.rb, line 20
20: def cache_responses?
21: @cache_responses
22: end
# File lib/typhoeus/remote_method.rb, line 44
44: def call_response_blocks(result, args, options)
45: key = args_options_key(args, options)
46: @response_blocks[key].each {|block| block.call(result)}
47: @response_blocks.delete(key)
48: @called_methods.delete(key)
49: end
# File lib/typhoeus/remote_method.rb, line 32
32: def calling(args, options)
33: @called_methods[args_options_key(args, options)] = true
34: end
# File lib/typhoeus/remote_method.rb, line 51
51: def clear_cache
52: @response_blocks = Hash.new {|h, k| h[k] = []}
53: @called_methods = {}
54: end
rippped from Sinatra. clean up stuff we don’t need later
# File lib/typhoeus/remote_method.rb, line 82
82: def compile(path)
83: path ||= ""
84: keys = []
85: if path.respond_to? :to_str
86: special_chars = %{. + ( )}
87: pattern =
88: path.gsub(/((:\w+)|[\*#{special_chars.join}])/) do |match|
89: case match
90: when "*"
91: keys << 'splat'
92: "(.*?)"
93: when *special_chars
94: Regexp.escape(match)
95: else
96: keys << $2[1..1]
97: "([^/?&#]+)"
98: end
99: end
100: [/^#{pattern}$/, keys]
101: elsif path.respond_to? :match
102: [path, keys]
103: else
104: raise TypeError, path
105: end
106: end
# File lib/typhoeus/remote_method.rb, line 67
67: def interpolate_path_with_arguments(args)
68: interpolated_path = @path
69: argument_names.each do |arg|
70: interpolated_path = interpolated_path.gsub(":#{arg}", args[arg].to_s)
71: end
72: interpolated_path
73: end
# File lib/typhoeus/remote_method.rb, line 24
24: def memoize_responses?
25: @memoize_responses
26: end
# File lib/typhoeus/remote_method.rb, line 56
56: def merge_options(new_options)
57: merged = options.merge(new_options)
58: if options.has_key?(:params) && new_options.has_key?(:params)
59: merged[:params] = options[:params].merge(new_options[:params])
60: end
61: argument_names.each {|a| merged.delete(a)}
62: merged.delete(:on_success) if merged[:on_success].nil?
63: merged.delete(:on_failure) if merged[:on_failure].nil?
64: merged
65: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.