Class: RoxClient::RSpec::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/rox-client-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.



23
24
25
26
27
28
# File 'lib/rox-client-rspec/config.rb', line 23

def initialize
  @servers = []
  @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.



20
21
22
# File 'lib/rox-client-rspec/config.rb', line 20

def cache_payload=(value)
  @cache_payload = value
end

#load_warningsObject (readonly)

Returns the value of attribute load_warnings.



21
22
23
# File 'lib/rox-client-rspec/config.rb', line 21

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.



20
21
22
# File 'lib/rox-client-rspec/config.rb', line 20

def local_mode=(value)
  @local_mode = value
end

Sets the attribute print_payload

Parameters:

  • value

    the value to set the attribute print_payload to.



20
21
22
# File 'lib/rox-client-rspec/config.rb', line 20

def print_payload=(value)
  @print_payload = value
end

#projectObject (readonly)

Returns the value of attribute project.



21
22
23
# File 'lib/rox-client-rspec/config.rb', line 21

def project
  @project
end

#publish=(value) ⇒ Object (writeonly)

Sets the attribute publish

Parameters:

  • value

    the value to set the attribute publish to.



20
21
22
# File 'lib/rox-client-rspec/config.rb', line 20

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.



20
21
22
# File 'lib/rox-client-rspec/config.rb', line 20

def save_payload=(value)
  @save_payload = value
end

#serverObject (readonly)

Returns the value of attribute server.



21
22
23
# File 'lib/rox-client-rspec/config.rb', line 21

def server
  @server
end

#workspaceObject

Returns the value of attribute workspace.



21
22
23
# File 'lib/rox-client-rspec/config.rb', line 21

def workspace
  @workspace
end

Instance Method Details

#client_optionsObject



49
50
51
52
53
54
55
56
57
58
# File 'lib/rox-client-rspec/config.rb', line 49

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

#loadObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/rox-client-rspec/config.rb', line 60

def load

  @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 @servers.empty?
    @load_warnings << "No server defined"
  elsif !@server_name
    @load_warnings << "No server name given"
  elsif !@server
    @load_warnings << "Unknown server '#{@server_name}'"
  end

  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



34
35
36
# File 'lib/rox-client-rspec/config.rb', line 34

def servers
  @servers.dup
end

#setup!Object

Plugs ROX utilities into RSpec.



39
40
41
42
43
# File 'lib/rox-client-rspec/config.rb', line 39

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