Class: ProbeDockRSpec::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/probe_dock_rspec/config.rb

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



28
29
30
31
32
33
34
# File 'lib/probe_dock_rspec/config.rb', line 28

def initialize
  @servers = []
  @server = Server.new
  @project = Project.new
  @publish, @local_mode, @cache_payload, @print_payload, @save_payload = false, false, false, false, false
  @load_warnings = []
end

Instance Attribute Details

#cache_payload=(value) ⇒ Object (writeonly)

Sets the attribute cache_payload

Parameters:

  • value

    the value to set the attribute cache_payload to.



25
26
27
# File 'lib/probe_dock_rspec/config.rb', line 25

def cache_payload=(value)
  @cache_payload = value
end

#load_warningsObject (readonly)

Returns the value of attribute load_warnings.



26
27
28
# File 'lib/probe_dock_rspec/config.rb', line 26

def load_warnings
  @load_warnings
end

#local_mode=(value) ⇒ Object (writeonly)

Sets the attribute local_mode

Parameters:

  • value

    the value to set the attribute local_mode to.



25
26
27
# File 'lib/probe_dock_rspec/config.rb', line 25

def local_mode=(value)
  @local_mode = value
end

Sets the attribute print_payload

Parameters:

  • value

    the value to set the attribute print_payload to.



25
26
27
# File 'lib/probe_dock_rspec/config.rb', line 25

def print_payload=(value)
  @print_payload = value
end

#projectObject (readonly)

Returns the value of attribute project.



26
27
28
# File 'lib/probe_dock_rspec/config.rb', line 26

def project
  @project
end

#publish=(value) ⇒ Object (writeonly)

Sets the attribute publish

Parameters:

  • value

    the value to set the attribute publish to.



25
26
27
# File 'lib/probe_dock_rspec/config.rb', line 25

def publish=(value)
  @publish = value
end

#save_payload=(value) ⇒ Object (writeonly)

Sets the attribute save_payload

Parameters:

  • value

    the value to set the attribute save_payload to.



25
26
27
# File 'lib/probe_dock_rspec/config.rb', line 25

def save_payload=(value)
  @save_payload = value
end

#serverObject (readonly)

Returns the value of attribute server.



26
27
28
# File 'lib/probe_dock_rspec/config.rb', line 26

def server
  @server
end

#workspaceObject

Returns the value of attribute workspace.



26
27
28
# File 'lib/probe_dock_rspec/config.rb', line 26

def workspace
  @workspace
end

Instance Method Details

#check!Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/probe_dock_rspec/config.rb', line 104

def check!

  configs = [ home_config_file, working_config_file ]
  actual_configs = configs.select{ |f| File.exists? f }

  if actual_configs.empty?
    @load_warnings << %|no config file found, looking for:\n     #{configs.join "\n     "}|
  end

  if @servers.empty?
    @load_warnings << "No server defined"
  elsif !@server_name && !@server.name
    @load_warnings << "No server name given"
  end
end

#client_optionsObject



55
56
57
58
59
60
61
62
63
64
# File 'lib/probe_dock_rspec/config.rb', line 55

def client_options
  {
    publish: @publish,
    local_mode: @local_mode,
    workspace: @workspace,
    cache_payload: @cache_payload,
    print_payload: @print_payload,
    save_payload: @save_payload
  }.select{ |k,v| !v.nil? }
end

#load!Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/probe_dock_rspec/config.rb', line 66

def load!

  @server.clear
  @servers.clear

  @load_warnings = []
  return unless config = load_config_files

  @publish = parse_env_flag :publish, !!config[:publish]
  @server_name = parse_env_option(:server) || config[:server]
  @local_mode = parse_env_flag(:local) || !!config[:local]

  self.workspace = parse_env_option(:workspace) || config[:workspace]
  @cache_payload = parse_env_flag :cache_payload, !!config[:payload][:cache]
  @print_payload = parse_env_flag :print_payload, !!config[:payload][:print]
  @save_payload = parse_env_flag :save_payload, !!config[:payload][:save]

  @servers, server = build_servers config

  if server
    @server = server
  else
    @server.name = @server_name
  end

  {
    api_url: parse_env_option(:server_api_url),
    api_token: parse_env_option(:server_api_token),
    project_api_id: parse_env_option(:server_project_api_id)
  }.each{ |k,v| @server.send "#{k}=", v if v }

  project_options = config[:project]
  project_options.merge! api_id: @server.project_api_id if @server and @server.project_api_id
  @project.update project_options

  self
end

#serversObject



40
41
42
# File 'lib/probe_dock_rspec/config.rb', line 40

def servers
  @servers.dup
end

#setup!Object

Plugs Probe Dock utilities into RSpec.



45
46
47
48
49
# File 'lib/probe_dock_rspec/config.rb', line 45

def setup!
  ::RSpec.configure do |c|
    c.add_formatter Formatter
  end
end