right_support 2.5.1 → 2.5.2

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.
@@ -82,8 +82,14 @@ module RightSupport::Config
82
82
  # (ArgumentError):: If configuration source can`t be loaded
83
83
  def load(something)
84
84
  return_value = nil
85
+ error_message = ''
85
86
  @configuration_source = something
86
- raise ArgumentError, "Can't coerce #{something} into YAML/Hash" unless (return_value = YAMLConfig.read(something))
87
+ begin
88
+ return_value = YAMLConfig.read(something)
89
+ rescue Exception => e
90
+ error_message = "#{e}"
91
+ end
92
+ raise ArgumentError, "Can't coerce #{something.inspect} into YAML/Hash. #{error_message}" unless return_value
87
93
  return_value
88
94
  end
89
95
 
@@ -49,7 +49,7 @@ module RightSupport::Data
49
49
  # === Return
50
50
  # @return [TrueClass|FalseClass] true if clazz is hash-like, false otherwise
51
51
  def self.hash_like?(clazz)
52
- clazz.public_instance_methods.include?('has_key?')
52
+ clazz.public_method_defined?('has_key?')
53
53
  end
54
54
 
55
55
  # Gets a value from a (deep) hash using a path given as an array of keys.
@@ -127,8 +127,15 @@ module RightSupport::DB
127
127
  @@config
128
128
  end
129
129
 
130
+ def env_config
131
+ env = ENV['RACK_ENV']
132
+ raise MissingConfiguration, "CassandraModel config is missing a '#{ENV['RACK_ENV']}' section" \
133
+ unless !@@config.nil? && @@config.keys.include?(env) && @@config[env]
134
+ @@config[env]
135
+ end
136
+
130
137
  def config=(value)
131
- @@config = value
138
+ @@config = normalize_config(value) unless value.nil?
132
139
  end
133
140
 
134
141
  def logger=(l)
@@ -194,9 +201,7 @@ module RightSupport::DB
194
201
  def conn()
195
202
  @@connections ||= {}
196
203
 
197
- # TODO remove hidden dependency on ENV['RACK_ENV'] (maybe require config= to accept a sub hash?)
198
- config = @@config[ENV["RACK_ENV"]]
199
- raise MissingConfiguration, "CassandraModel config is missing a '#{ENV['RACK_ENV']}' section" unless config
204
+ config = env_config
200
205
 
201
206
  thrift_client_options = {:timeout => RightSupport::DB::CassandraModel::DEFAULT_TIMEOUT}
202
207
  thrift_client_options.merge!({:protocol => Thrift::BinaryProtocolAccelerated})\
@@ -265,7 +270,7 @@ module RightSupport::DB
265
270
  columns.merge!(chunk)
266
271
  if chunk.size == opt[:count]
267
272
  # Assume there are more chunks, use last key as start of next get
268
- opt[:start] = chunk.keys.last
273
+ opt[:start] = chunk.keys.sort.last
269
274
  else
270
275
  # This must be the last chunk
271
276
  break
@@ -400,7 +405,7 @@ module RightSupport::DB
400
405
  end
401
406
  if chunk.size == count
402
407
  # Assume there are more chunks, use last key as start of next get
403
- start = chunk.keys.last
408
+ start = chunk.keys.sort.last
404
409
  else
405
410
  # This must be the last chunk
406
411
  break
@@ -493,8 +498,7 @@ module RightSupport::DB
493
498
  # === Return
494
499
  # true:: Always return true
495
500
  def reconnect
496
- config = @@config[ENV["RACK_ENV"]]
497
- raise MissingConfiguration, "CassandraModel config is missing a '#{ENV['RACK_ENV']}' section" unless config
501
+ config = env_config
498
502
 
499
503
  return false if keyspace.nil?
500
504
 
@@ -516,6 +520,33 @@ module RightSupport::DB
516
520
  conn.ring
517
521
  end
518
522
 
523
+ private
524
+
525
+ # Massage configuration hash into a standard form.
526
+ # @return the config hash, with contents normalized
527
+ def normalize_config(untrasted_config)
528
+ untrasted_config.each do |env, config|
529
+ raise MissingConfiguration, "CassandraModel config is broken, a '#{ENV['RACK_ENV']}' missing 'server' option" \
530
+ unless config.keys.include?('server')
531
+ server = config['server']
532
+
533
+ if server.is_a?(String)
534
+ # Strip surrounding brackets, in case Ops put a YAML array into an input value
535
+ if server.start_with?('[') && server.end_with?(']')
536
+ server = server[1..-2]
537
+ end
538
+
539
+ # Transform comma-separated host lists into an Array
540
+ if server =~ /,/
541
+ server = server.split(/\s*,\s*/)
542
+ end
543
+ end
544
+
545
+ config['server'] = server
546
+
547
+ config
548
+ end
549
+ end
519
550
  end # self
520
551
 
521
552
  attr_accessor :key, :attributes
@@ -7,8 +7,8 @@ spec = Gem::Specification.new do |s|
7
7
  s.required_ruby_version = Gem::Requirement.new(">= 1.8.7")
8
8
 
9
9
  s.name = 'right_support'
10
- s.version = '2.5.1'
11
- s.date = '2012-09-25'
10
+ s.version = '2.5.2'
11
+ s.date = '2012-09-28'
12
12
 
13
13
  s.authors = ['Tony Spataro', 'Sergey Sergyenko', 'Ryan Williamson', 'Lee Kirchhoff', 'Sergey Enin']
14
14
  s.email = 'support@rightscale.com'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: right_support
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 2
8
8
  - 5
9
- - 1
10
- version: 2.5.1
9
+ - 2
10
+ version: 2.5.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tony Spataro
@@ -19,7 +19,7 @@ autorequire:
19
19
  bindir: bin
20
20
  cert_chain: []
21
21
 
22
- date: 2012-09-25 00:00:00 -07:00
22
+ date: 2012-09-28 00:00:00 -07:00
23
23
  default_executable:
24
24
  dependencies: []
25
25