Skip to content
This repository has been archived by the owner on Aug 25, 2024. It is now read-only.

Commit

Permalink
Merge pull request #4 from dreikanter/logux_rails_integration
Browse files Browse the repository at this point in the history
Integrate logux_rails gem
  • Loading branch information
dsalahutdinov authored Oct 5, 2019
2 parents d1039be + ac267f5 commit 947ba2b
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 12 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ services:
before_script:
- unset BUNDLE_GEMFILE
- docker-compose run app bundle install
- docker-compose run app bundle exec appraisal install
script:
- docker-compose run app bundle exec appraisal rspec
- docker-compose run app bundle exec rspec
- docker-compose run app bundle exec rubocop
12 changes: 8 additions & 4 deletions lib/logux/action_caller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@ def initialize(action:, meta:)
end

def call!
logger.debug(
"Searching action for Logux action: #{action}, meta: #{meta}"
)
format(action_controller.public_send(action.action_type))
Logux.watch_action { call_action }
rescue Logux::UnknownActionError, Logux::UnknownChannelError => e
logger.warn(e)
format(nil)
end

protected

def call_action
logger.debug("Searching Logux action: #{action}, meta: #{meta}")
format(action_controller.public_send(action.action_type))
end

private

def format(response)
Expand Down
21 changes: 21 additions & 0 deletions lib/logux/action_watcher.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

module Logux
class ActionWatcher
def self.call(options = {}, &block)
new(options).call(&block)
end

attr_reader :options

def initialize(options = {})
raise ArgumentError, :options unless options.is_a?(Hash)

@options = options
end

def call
yield
end
end
end
13 changes: 13 additions & 0 deletions lib/logux/rack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ def initialize(msg, meta: nil)
autoload :Test, 'logux/test'
autoload :ErrorRenderer, 'logux/error_renderer'
autoload :Utils, 'logux/utils'
autoload :ActionWatcher, 'logux/action_watcher'

configurable %i[
action_watcher
action_watcher_options
auth_rule
logger
logux_host
Expand All @@ -68,6 +71,8 @@ def initialize(msg, meta: nil)
config.on_error = proc {}
config.auth_rule = proc { false }
config.render_backtrace_on_error = true
config.action_watcher = Logux::ActionWatcher
config.action_watcher_options = {}
end

module Rack
Expand Down Expand Up @@ -113,6 +118,14 @@ def logger
configuration.logger
end

def action_watcher
configuration.action_watcher.new(configuration.action_watcher_options)
end

def watch_action
action_watcher.call { yield }
end

def application
Logux::Rack::App
end
Expand Down
2 changes: 1 addition & 1 deletion lib/logux/rack/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def meta_params
end

def handle_processing_errors(logux_stream, exception)
Logux.configuration.on_error.call(exception)
Logux.configuration.on_error&.call(exception)
Logux.logger.error("#{exception}\n#{exception.backtrace.join("\n")}")
ensure
logux_stream.write(Logux::ErrorRenderer.new(exception).message)
Expand Down
4 changes: 3 additions & 1 deletion lib/logux/version.rb → lib/logux/rack/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

module Logux
VERSION = '0.1.0'
module Rack
VERSION = '0.1.0'
end
end
7 changes: 3 additions & 4 deletions logux-rack.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'logux/version'
require 'logux/rack/version'

Gem::Specification.new do |spec|
spec.name = 'logux-rack'
spec.version = Logux::VERSION
spec.version = Logux::Rack::VERSION
spec.authors = ['WildDima']
spec.email = ['dtopornin@gmail.com']
spec.summary = 'Rack application backend for Logux proxy server'
Expand Down Expand Up @@ -49,12 +49,11 @@ Gem::Specification.new do |spec|
spec.add_dependency 'configurations'
spec.add_dependency 'nanoid'
spec.add_dependency 'rack', '~> 2.0'
spec.add_dependency 'rest-client'
spec.add_dependency 'rest-client', '>= 1.7.3', '< 3'
spec.add_dependency 'sinatra', '>= 2.0', '< 3'
spec.add_development_dependency 'bundler', '~> 1.16'
spec.add_development_dependency 'coveralls'
spec.add_development_dependency 'factory_bot'
spec.add_development_dependency 'pg'
spec.add_development_dependency 'pry'
spec.add_development_dependency 'pry-byebug'
spec.add_development_dependency 'puma'
Expand Down

0 comments on commit 947ba2b

Please sign in to comment.