Class: Req
- Inherits:
-
Thor
- Object
- Thor
- Req
- Defined in:
- lib/req-cli.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#state ⇒ Object
Returns the value of attribute state.
Class Method Summary collapse
Instance Method Summary collapse
- #clear ⇒ Object
- #context(name) ⇒ Object
- #contexts ⇒ Object
- #environment(name) ⇒ Object
- #environments ⇒ Object
- #exec(requestname) ⇒ Object
- #requests ⇒ Object
- #status ⇒ Object
- #variable(name, value) ⇒ Object
- #variables ⇒ Object
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
20 21 22 |
# File 'lib/req-cli.rb', line 20 def config @config end |
#state ⇒ Object
Returns the value of attribute state.
20 21 22 |
# File 'lib/req-cli.rb', line 20 def state @state end |
Class Method Details
Instance Method Details
#clear ⇒ Object
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 |
#contexts ⇒ Object
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 |
#environments ⇒ Object
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, backend.execute end |
#requests ⇒ Object
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 |
#status ⇒ Object
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 |
#variables ⇒ Object
77 78 79 80 |
# File 'lib/req-cli.rb', line 77 def variables init @state.variables.each {|key, val| put "#{key}: #{val}" } end |