Class: Req

Inherits:
Thor
  • Object
show all
Defined in:
lib/req-cli.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configObject

Returns the value of attribute config.



20
21
22
# File 'lib/req-cli.rb', line 20

def config
  @config
end

#stateObject

Returns the value of attribute state.



20
21
22
# File 'lib/req-cli.rb', line 20

def state
  @state
end

Class Method Details

.create_with_config(config) ⇒ Object



24
25
26
27
28
29
# File 'lib/req-cli.rb', line 24

def self.create_with_config(config)
  req = Req.new
  req.config = config
  req.state = State.new
  req
end

Instance Method Details

#clearObject



92
93
94
95
# File 'lib/req-cli.rb', line 92

def clear
  @state = State.new
  save_state
end

#context(name) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/req-cli.rb', line 38

def context(name)
  init
  if @config.contexts.any? { |ctx| ctx.name == name }
    puts "switching to context #{name}"
    @state.context = name
    save_state
  else
    puts "context not found"
    exit 1
  end
end

#contextsObject



32
33
34
35
# File 'lib/req-cli.rb', line 32

def contexts
  init # TODO avoid this
  @config.contexts.each {|ctx| puts ctx.name }
end

#environment(name) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/req-cli.rb', line 57

def environment(name)
  init
  if @config.has_environment? name
    puts "switching to environment #{name}"
    @state.environment = name
    save_state
  else
    puts "environment not found"
    exit 1
  end
end

#environmentsObject



51
52
53
54
# File 'lib/req-cli.rb', line 51

def environments
  init
  @config.environments.each {|env| puts env.name }
end

#exec(requestname) ⇒ Object



100
101
102
103
104
105
106
107
# File 'lib/req-cli.rb', line 100

def exec(requestname)
  init
  valid_for_execution?
  request = @config.get_request(requestname)
  prepared_request = RequestFactory.create(@config, @state, request)
  backend = CurlBackend.new prepared_request, options
  backend.execute
end

#requestsObject



110
111
112
113
# File 'lib/req-cli.rb', line 110

def requests
  init
  @config.requests.each {|req| puts "#{req.name} \t#{req.method} \t#{req.path}"}
end

#statusObject



83
84
85
86
87
88
89
# File 'lib/req-cli.rb', line 83

def status
  init
  puts "context: #{@state.context}"
  puts "environment: #{@state.environment}"
  puts "variables: "
  @state.variables.each { |key,val| puts "    #{key}: #{val}" }
end

#variable(name, value) ⇒ Object



70
71
72
73
74
# File 'lib/req-cli.rb', line 70

def variable(name, value)
  init
  @state.variables[name] = value
  save_state
end

#variablesObject



77
78
79
80
# File 'lib/req-cli.rb', line 77

def variables
  init
  @state.variables.each {|key, val| put "#{key}: #{val}" }
end