Module: Polyseerio::SDK::Helper

Defined in:
lib/sdk/helper.rb

Overview

SDK helpers.

Class Method Summary collapse

Class Method Details

.accumulate_procs(*args) ⇒ Object

Accumulates a function type from a map into an accumulator.



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/sdk/helper.rb', line 29

def self.accumulate_procs(*args)
  proc do |type, map, name, acc|
    unless map.key? name
      raise "SDK factory could not find a #{type} #{name}."
    end

    acc[name] = map.fetch(name)

    acc
  end.curry.call(*args)
end

.instance_to_uri(instance) ⇒ Object

Takes an instance and returns a uri.



20
21
22
23
24
25
26
# File 'lib/sdk/helper.rb', line 20

def self.instance_to_uri(instance)
  URL.get_resource_path(
    instance.type,
    eid: instance.eid,
    id: instance.id
  )
end

.reduce_options(options, copts = {}, defaults = {}) ⇒ Object

Reduce method options with client options and method defaults



42
43
44
# File 'lib/sdk/helper.rb', line 42

def self.reduce_options(options, copts = {}, defaults = {})
  defaults.merge(copts).merge(options)
end

.remove_non_resolving_values(hash) ⇒ Object

Takes a hash and returns a new one that only contains values that are blocks / procs / anything callable aka resolvable.



11
12
13
14
15
16
17
# File 'lib/sdk/helper.rb', line 11

def self.remove_non_resolving_values(hash)
  hash.each_with_object({}) do |(key, value), acc|
    acc[key] = value if value.respond_to? :call

    acc
  end
end

.resolve_eid(options) ⇒ Object

Determine the eid given a reduced options hash



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/sdk/helper.rb', line 47

def self.resolve_eid(options)
  return options[:environment] if options.key? :environment

  if options[:deduce]
    env = options.fetch(:env)

    return ENV.fetch env if ENV.key? env
  end

  Constant::DEFAULT_ENVIRONMENT
end