Class: Localhook::Command
- Inherits:
-
CLAide::Command
- Object
- CLAide::Command
- Localhook::Command
- Defined in:
- lib/localhook/command.rb
Instance Attribute Summary collapse
-
#local_server ⇒ Object
readonly
Returns the value of attribute local_server.
-
#remote_server ⇒ Object
readonly
Returns the value of attribute remote_server.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(argv) ⇒ Command
constructor
A new instance of Command.
- #run ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(argv) ⇒ Command
Returns a new instance of Command.
14 15 16 17 18 19 |
# File 'lib/localhook/command.rb', line 14 def initialize(argv) @remote_server = argv.shift_argument @local_server = argv.shift_argument @token = argv.option('token') super end |
Instance Attribute Details
#local_server ⇒ Object (readonly)
Returns the value of attribute local_server.
9 10 11 |
# File 'lib/localhook/command.rb', line 9 def local_server @local_server end |
#remote_server ⇒ Object (readonly)
Returns the value of attribute remote_server.
9 10 11 |
# File 'lib/localhook/command.rb', line 9 def remote_server @remote_server end |
Class Method Details
.options ⇒ Object
21 22 23 24 25 |
# File 'lib/localhook/command.rb', line 21 def self. [ ['--token=<token>', 'Authentication Token'] ].concat(super) end |
Instance Method Details
#run ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/localhook/command.rb', line 39 def run EventMachine.run do puts "forward remote server (#{@remote_server}) webhooks to #{@local_server}" @forwarder = WebhookForwarder.new(@local_server) @source = EventSource.new(@remote_server, @forwarder, @token) @source.error do |error| puts "error connecting to eventsource: #{error}" end @source.start end end |
#validate! ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/localhook/command.rb', line 27 def validate! if @remote_server.nil? help! "missing remote-server parameter" end if @local_server.nil? help! "missing local-server parameter" end if @token.nil? help! "missing token" end end |