Module: Eco::API::Session::Config::Apis::EnviroSpaces

Includes:
SpaceHelpers
Included in:
Eco::API::Session::Config::Apis
Defined in:
lib/eco/api/session/config/apis/enviro_spaces.rb

Instance Method Summary collapse

Methods included from SpaceHelpers

#set_options_space!, #space_option, #space_option?

Instance Method Details

#active_spaceObject



20
21
22
# File 'lib/eco/api/session/config/apis/enviro_spaces.rb', line 20

def active_space
  active_api&.space || space_option
end

#any_defined?(*names, space: space_option) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
54
55
# File 'lib/eco/api/session/config/apis/enviro_spaces.rb', line 51

def any_defined?(*names, space: space_option)
  [names].flatten.any? do |name|
    api?(name, space: space)
  end
end

#api?(name, space: space_option) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/eco/api/session/config/apis/enviro_spaces.rb', line 42

def api?(name, space: space_option)
  apis(space).key?(name)
end

#apis(space = space_option) ⇒ Object

APIs of a particualr space



29
30
31
# File 'lib/eco/api/session/config/apis/enviro_spaces.rb', line 29

def apis(space = space_option)
  api_space(space)
end

#apis?(space = nil) ⇒ Boolean

Any APIs (of any space or in a particular space)

Returns:

  • (Boolean)


34
35
36
37
38
39
40
# File 'lib/eco/api/session/config/apis/enviro_spaces.rb', line 34

def apis?(space = nil)
  return apis(space).any? unless space.nil?

  spaces.each_key.any? do |space|
    apis?(space)
  end
end

#defined?(name, space: space_option) ⇒ Boolean

Deprecated

Returns:

  • (Boolean)


47
48
49
# File 'lib/eco/api/session/config/apis/enviro_spaces.rb', line 47

def defined?(name, space: space_option)
  apis(space).key?(name)
end

#enviro_spaces(name) ⇒ Array<Symbol>

Returns the spaces where the enviro name has an api defined.

Returns:

  • (Array<Symbol>)

    the spaces where the enviro name has an api defined



59
60
61
62
63
# File 'lib/eco/api/session/config/apis/enviro_spaces.rb', line 59

def enviro_spaces(name)
  spaces.keys.select do |space|
    api?(name, space: space)
  end
end

#enviro_spaces?(name) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/eco/api/session/config/apis/enviro_spaces.rb', line 71

def enviro_spaces?(name)
  enviro_spaces(name).any?
end

#enviro_spaces_str(name) ⇒ Object



65
66
67
68
69
# File 'lib/eco/api/session/config/apis/enviro_spaces.rb', line 65

def enviro_spaces_str(name)
  return '' unless enviro_spaces?(name)

  ":#{enviro_spaces(name).join(', :')}"
end

#enviros(space) ⇒ Object



24
25
26
# File 'lib/eco/api/session/config/apis/enviro_spaces.rb', line 24

def enviros(space)
  apis(space).keys
end

#missing_api_message(name, space: space_option) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/eco/api/session/config/apis/enviro_spaces.rb', line 75

def missing_api_message(name, space: space_option)
  space ||= space_option

  msg  = "Missing credentials for "
  msg << "#{full_name(name, space: space)} Api env."

  if enviro_spaces?(name)
    msg << "\n  Available space(s) for '#{name}' enviro: "
    msg << enviro_spaces_str(name)
    msg << "\n"
  end

  msg
end