Module: Numerics
- Defined in:
- lib/numerics.rb,
lib/numerics/connection.rb
Defined Under Namespace
Classes: Connection
Constant Summary collapse
- VERSION =
'0.2.4'
Class Method Summary collapse
- .config(arg, env = nil) ⇒ Object
- .connect(arg, env = nil) ⇒ Object
- .global_connection ⇒ Object
- .global_connection=(gc) ⇒ Object
-
.method_missing(method, *args, &block) ⇒ Object
@@ check syntax.
- .respond_to?(method) ⇒ Boolean
Class Method Details
.config(arg, env = nil) ⇒ Object
50 51 52 |
# File 'lib/numerics.rb', line 50 def self.config(arg, env=nil) @global_connection = self.connect(arg, env) end |
.connect(arg, env = nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/numerics.rb', line 13 def self.connect(arg, env=nil) config = if arg.is_a?(Hash) arg else if arg.match(/\.json$/) File.open(arg){ |f| Yajl::Parser.parse(f) } elsif arg.match(/\.ya?ml$/) YAML::load_file(arg) else nil end end if !config raise "Only json and yaml config files supported" end if env config = config[env.to_s] || config[env.to_sym] if !config raise "No #{env} found in #{arg}" end end access_key = config[:access_key] || config['access_key'] secret_key = config[:secret_key] || config['secret_key'] host = config[:host] || config['host'] # nil means use the default port = config[:port] || config['port'] # nil means use the default disabled = config[:disabled] || config['disabled'] if !access_key && !secret_key raise ArgumentError, 'Numerics.connect(config_file, env=nil) or Numerics.connect(:access_key => access_key, :secret_key => :secret_key)' end Numerics::Connection.new(access_key, secret_key, host, port, disabled) end |
.global_connection ⇒ Object
54 55 56 |
# File 'lib/numerics.rb', line 54 def self.global_connection @global_connection end |
.global_connection=(gc) ⇒ Object
58 59 60 |
# File 'lib/numerics.rb', line 58 def self.global_connection=(gc) @global_connection = gc end |
.method_missing(method, *args, &block) ⇒ Object
@@ check syntax
67 68 69 70 71 72 73 74 |
# File 'lib/numerics.rb', line 67 def self.method_missing(method, *args, &block) if self.respond_to?(method) @global_connection.send(method, *args, &block) else super end end |
.respond_to?(method) ⇒ Boolean
62 63 64 |
# File 'lib/numerics.rb', line 62 def self.respond_to?(method) !@global_connection.nil? && @global_connection.respond_to?(method) end |