Module: Subaru::Helper
- Defined in:
- lib/subaru/helper.rb
Overview
Sinatra helper
Instance Method Summary collapse
-
#device_with_name(name) ⇒ Object
Create device object with name.
-
#json_with_object(object, opts = {pretty: settings.subaru_config[:global][:pretty_json]}) ⇒ Object
Convert object into JSON.
-
#valid_token?(token, method = :any) ⇒ Boolean
Validate auth token, if configured.
Instance Method Details
#device_with_name(name) ⇒ Object
Create device object with name
37 38 39 40 41 42 43 |
# File 'lib/subaru/helper.rb', line 37 def device_with_name(name) c = settings.[:devices][name] return Object.const_get("Subaru::Definitions::#{c[:definition]}").new(c) if c rescue => e puts e. return nil end |
#json_with_object(object, opts = {pretty: settings.subaru_config[:global][:pretty_json]}) ⇒ Object
Convert object into JSON.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/subaru/helper.rb', line 11 def json_with_object(object, opts = {pretty: settings.[:global][:pretty_json]}) return '{}' if object.nil? if opts[:pretty] == true opts = { indent: ' ', space: ' ', object_nl: "\n", array_nl: "\n" } end JSON.fast_generate(object, opts) rescue => e puts e. raise end |
#valid_token?(token, method = :any) ⇒ Boolean
Validate auth token, if configured.
28 29 30 31 32 |
# File 'lib/subaru/helper.rb', line 28 def valid_token?(token, method = :any) tokens = settings.[:global][:auth_tokens][method] return true if tokens.nil? tokens.include?(token) end |