Class: EacRubyUtils::Rspec::StubbedSsh

Inherits:
Object
  • Object
show all
Defined in:
lib/eac_ruby_utils/rspec/stubbed_ssh.rb

Constant Summary collapse

DEFAULT_ENVVAR_NAME =
'STUBBED_SSH_URL'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(envvar_name) ⇒ StubbedSsh

Returns a new instance of StubbedSsh.


20
21
22
# File 'lib/eac_ruby_utils/rspec/stubbed_ssh.rb', line 20

def initialize(envvar_name)
  @envvar_name = envvar_name
end

Instance Attribute Details

#envvar_nameObject (readonly)

Returns the value of attribute envvar_name


18
19
20
# File 'lib/eac_ruby_utils/rspec/stubbed_ssh.rb', line 18

def envvar_name
  @envvar_name
end

Class Method Details

.defaultObject


13
14
15
# File 'lib/eac_ruby_utils/rspec/stubbed_ssh.rb', line 13

def default
  @default ||= new(DEFAULT_ENVVAR_NAME)
end

Instance Method Details

#build_envObject


38
39
40
41
# File 'lib/eac_ruby_utils/rspec/stubbed_ssh.rb', line 38

def build_env
  validate!
  ::EacRubyUtils::Envs::SshEnv.new(provided_url)
end

#provided_urlObject


34
35
36
# File 'lib/eac_ruby_utils/rspec/stubbed_ssh.rb', line 34

def provided_url
  ENV[envvar_name]
end

#validateObject


24
25
26
27
28
# File 'lib/eac_ruby_utils/rspec/stubbed_ssh.rb', line 24

def validate
  return nil if provided_url.present?

  "Environment variable \"#{envvar_name}\" unprovided or blank"
end

#validate!Object


30
31
32
# File 'lib/eac_ruby_utils/rspec/stubbed_ssh.rb', line 30

def validate!
  validate.if_present { |v| raise v }
end