global_session 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -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 = 'global_session'
10
- s.version = '1.0.4'
11
- s.date = '2011-06-20'
10
+ s.version = '1.0.5'
11
+ s.date = '2011-07-26'
12
12
 
13
13
  s.authors = ['Tony Spataro']
14
14
  s.email = 'code@tracker.xeger.net'
@@ -52,21 +52,29 @@ module GlobalSession
52
52
  # you are integrating; see GlobalSession::Rails for more information.
53
53
  #
54
54
  class Configuration
55
- # Create a new Configuration objectt
55
+ # Create a new Configuration object
56
56
  #
57
57
  # === Parameters
58
- # config_File(String):: Absolute filesystem path to the configuration file
58
+ # config(String|Hash):: Absolute filesystem path to the configuration file, or Hash containing configuration
59
59
  # environment(String):: Config file section from which to read settings
60
60
  #
61
61
  # === Raise
62
62
  # MissingConfiguration:: if config file is missing or unreadable
63
63
  # TypeError:: if config file does not contain a YAML-serialized Hash
64
- def initialize(config_file, environment)
65
- @config_file = config_file
64
+ def initialize(config, environment)
65
+ if config.is_a?(Hash)
66
+ @config = config
67
+ elsif File.readable?(config)
68
+ data = YAML.load(File.read(config))
69
+ unless data.is_a?(Hash)
70
+ raise TypeError, "Configuration file #{File.basename(config)} must contain a hash as its top-level element"
71
+ end
72
+ @config = data
73
+ else
74
+ raise MissingConfiguration, "Missing or unreadable configuration file #{config}"
75
+ end
76
+
66
77
  @environment = environment
67
- raise MissingConfiguration, "Missing or unreadable configuration file" unless File.readable?(@config_file)
68
- @config = YAML.load(File.read(@config_file))
69
- raise TypeError, "#{config_file} must contain a Hash!" unless Hash === @config
70
78
  validate
71
79
  end
72
80
 
@@ -103,7 +111,7 @@ module GlobalSession
103
111
  elements.each do |element|
104
112
  object = object[element] if object
105
113
  if object.nil?
106
- msg = "#{File.basename(@config_file)} does not specify required element #{elements.map { |x| "['#{x}']"}.join('')}"
114
+ msg = "Configuration does not specify required element #{elements.map { |x| "['#{x}']"}.join('')}"
107
115
  raise MissingConfiguration, msg
108
116
  end
109
117
  end
@@ -166,7 +166,11 @@ module GlobalSession
166
166
  # env(Hash): Rack environment
167
167
  # e(Exception): error that happened
168
168
  def handle_error(activity, env, e)
169
- env['rack.logger'].error("#{e.class} while #{activity}: #{e} #{e.backtrace}") if env['rack.logger']
169
+ if env['rack.logger']
170
+ msg = "#{e.class} while #{activity}: #{e}"
171
+ msg += " #{e.backtrace}" unless e.is_a?(ExpiredSession)
172
+ env['rack.logger'].error(msg)
173
+ end
170
174
 
171
175
  if e.is_a?(ClientError) || e.is_a?(SecurityError)
172
176
  env['global_session.error'] = e
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: global_session
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 4
10
- version: 1.0.4
9
+ - 5
10
+ version: 1.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tony Spataro
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-20 00:00:00 -07:00
18
+ date: 2011-07-26 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency