rails_bridge 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile.lock CHANGED
@@ -16,7 +16,7 @@ GIT
16
16
  PATH
17
17
  remote: .
18
18
  specs:
19
- rails_bridge (0.0.5)
19
+ rails_bridge (0.0.6)
20
20
  activesupport
21
21
  rails_bridge
22
22
  typhoeus (~> 0.2.0)
data/README.rdoc CHANGED
@@ -152,7 +152,7 @@ Default values can be set for a group of requests by sub-classing RailsBridge::C
152
152
 
153
153
  === Setting global defaults
154
154
 
155
- Global default values can be set directly on the RailsBridge::ContentBridge class. They are used by all inheriting sub-classes unless overridden by the sub-class.
155
+ Global default values can be set directly on the RailsBridge::ContentBridge class. They are used by all inheriting sub-classes unless overridden by the sub-class.
156
156
 
157
157
  RailsBridge::ContentBridge.logger = Logger.new(STDOUT)
158
158
  RailsBridge::ContentBridge.cache = ActiveSupport::Cache::MemCacheStore(:compress => true)
@@ -163,7 +163,7 @@ I recommend putting these declaration in an initializer file under config/initia
163
163
 
164
164
  === Overriding request values on execution
165
165
 
166
- All defined values for a request can be overridden at runtime by passing them in as options to the get method:
166
+ All defined values for a request can be specified at runtime by passing them in as options to the get method. All parameters passed this way will override existing values, with the exception of :params, which are merged with those defined at the request declaration and class level.
167
167
 
168
168
  content = RailsBridge::ContentBridge.get_server_com( :params=>{:p1=>'p1'}, :request_timeout=>2000, :cache_timeout=>0 )
169
169
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.6
1
+ 0.0.7
@@ -52,11 +52,8 @@ module RailsBridge
52
52
  logger.debug "get key: #{key}"
53
53
  content = self.cache.fetch(key, :race_condition_ttl=>5.seconds)
54
54
  end
55
-
56
55
 
57
- def get_remote_content( remote, options={} )
58
- hydra = Typhoeus::Hydra.hydra # the singleton Hydra
59
- hydra.disable_memoization
56
+ def process_remote_and_options( remote, options )
60
57
  if remote.is_a? Symbol
61
58
  raise "Undefined content_request :#{remote}" unless remote = @@content_requests[remote]
62
59
  end
@@ -67,7 +64,7 @@ module RailsBridge
67
64
  if remote.is_a? RailsBridge::ContentRequest
68
65
  content_request = remote
69
66
  remote_url = content_request.url
70
- options[:params] ||= content_request.params
67
+ options[:params] = content_request.params.merge( options[:params] || {} )
71
68
  options[:request_timeout] ||= content_request.request_timeout
72
69
  options[:cache_timeout] ||= content_request.cache_timeout
73
70
  options[:default_content] ||= content_request.default_content
@@ -79,9 +76,15 @@ module RailsBridge
79
76
  options[:request_timeout] ||= self.request_timeout
80
77
  options[:cache_timeout] ||= self.cache_timeout
81
78
  options[:timeout] = options.delete(:request_timeout) # Rename the request timeout param for Typhoeus
79
+ [remote_url, options]
80
+ end
81
+
82
+ def get_remote_content( remote, options={} )
83
+ hydra = Typhoeus::Hydra.hydra # the singleton Hydra
84
+ hydra.disable_memoization
85
+ remote_url, options = process_remote_and_options( remote, options )
82
86
  default_content = options.delete(:default_content) || self.default_content
83
87
  # options[:verbose] = true # for debugging only
84
-
85
88
  request = Typhoeus::Request.new(remote_url, options)
86
89
  unless self.cache && request.cache_timeout && request.cache_timeout > 0 && result = cache_get( request.cache_key )
87
90
  result = default_content
@@ -37,7 +37,10 @@ module RailsBridge
37
37
  def host; @host || (self.content_bridge && self.content_bridge.host); end
38
38
  def port; @port || (self.content_bridge && self.content_bridge.port) || 80; end
39
39
  def path; @path || (self.content_bridge && self.content_bridge.path) || '/'; end
40
- def params; @params || (self.content_bridge && self.content_bridge.params); end
40
+ def params
41
+ content_bridge_params = (self.content_bridge && self.content_bridge.params) || {}
42
+ content_bridge_params.merge( @params || {} )
43
+ end
41
44
 
42
45
  def url= url
43
46
  uri = URI.parse( url )
data/rails_bridge.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rails_bridge}
8
- s.version = "0.0.6"
8
+ s.version = "0.0.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["shock"]
12
- s.date = %q{2011-01-04}
12
+ s.date = %q{2011-01-05}
13
13
  s.description = %q{Allows for easy embedding of content from a remote HTTP server and exporting of the Rails HTML layout into another template.}
14
14
  s.email = %q{billdoughty@capitalthought.com}
15
15
  s.extra_rdoc_files = [
@@ -45,6 +45,15 @@ describe RailsBridge::ContentBridge do
45
45
  ContentBridgeTest.get_chang(:default_content=>"YADA YADA").should == "YADA YADA"
46
46
  end
47
47
 
48
+ it "adds :params specified at level to those already defined", :focus=>false do
49
+ class ContentBridgeTestA < ContentBridgeTest
50
+ self.params = {:p1=>'p1'}
51
+ content_request( :yang, :params=>{:p3=>'p3'} )
52
+ end
53
+ remote_url, options = ContentBridgeTestA.process_remote_and_options(ContentBridgeTestA.content_requests[:yang], :params=>{:p2=>'p2'})
54
+ options[:params].should == {:p1=>'p1', :p2=>'p2', :p3=>'p3'}
55
+ end
56
+
48
57
  it "subclassing a ContentBridge does not change parent class' attributes", :focus=>false do
49
58
  class ContentBridgeTest2 < ContentBridgeTest
50
59
  self.default_content = "Some other content."
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 6
9
- version: 0.0.6
8
+ - 7
9
+ version: 0.0.7
10
10
  platform: ruby
11
11
  authors:
12
12
  - shock
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-04 00:00:00 -06:00
17
+ date: 2011-01-05 00:00:00 -06:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -331,7 +331,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
331
331
  requirements:
332
332
  - - ">="
333
333
  - !ruby/object:Gem::Version
334
- hash: -3957783545554095629
334
+ hash: 2020536357921793301
335
335
  segments:
336
336
  - 0
337
337
  version: "0"