Class: Pechkin::Main
- Inherits:
-
Object
- Object
- Pechkin::Main
- Defined in:
- lib/pechkin.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#handler ⇒ Object
readonly
Returns the value of attribute handler.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #add_auth ⇒ Object
-
#initialize(options) ⇒ Main
constructor
A new instance of Main.
- #parse_endpoint(endpoint) ⇒ Object
- #read_data(data) ⇒ Object
- #run ⇒ Object
- #run_server ⇒ Object
- #send_data ⇒ Object
Constructor Details
#initialize(options) ⇒ Main
Returns a new instance of Main.
38 39 40 |
# File 'lib/pechkin.rb', line 38 def initialize() @options = end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
36 37 38 |
# File 'lib/pechkin.rb', line 36 def configuration @configuration end |
#handler ⇒ Object (readonly)
Returns the value of attribute handler.
36 37 38 |
# File 'lib/pechkin.rb', line 36 def handler @handler end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
36 37 38 |
# File 'lib/pechkin.rb', line 36 def @options end |
Instance Method Details
#add_auth ⇒ Object
93 94 95 96 97 |
# File 'lib/pechkin.rb', line 93 def add_auth user, password = .add_auth.split(':') Pechkin::Auth::Manager.new(.htpasswd).add(user, password) puts IO.read(.htpasswd) end |
#parse_endpoint(endpoint) ⇒ Object
87 88 89 90 91 |
# File 'lib/pechkin.rb', line 87 def parse_endpoint(endpoint) endpoint.match(%r{^([^/]+)/(.+)}) do |m| [m[1], m[2]] end end |
#read_data(data) ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/pechkin.rb', line 78 def read_data(data) return data unless data.start_with?('@') file = data[1..-1] raise "File not found #{file}" unless File.exist?(file) IO.read(file) end |
#run ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/pechkin.rb', line 42 def run if .add_auth add_auth exit 0 end @configuration = Configuration.load_from_directory(.config_file) @handler = Handler.new(@configuration.channels) configuration.list if .list? return if .check? if .send_data send_data else run_server end end |
#run_server ⇒ Object
60 61 62 63 64 65 |
# File 'lib/pechkin.rb', line 60 def run_server Rack::Server.start(app: AppBuilder.new.build(handler, ), Port: .port, pid: .pid_file, Host: .bind_address) end |
#send_data ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/pechkin.rb', line 67 def send_data ch, msg = parse_endpoint(.send_data) raise "#{ch}/#{msg} not found" unless handler.(ch, msg) data = read_data(.data) handler.preview = .preview handler.handle(ch, msg, JSON.parse(data)) end |