logux_rails 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -0
  3. data/Appraisals +4 -0
  4. data/CHANGELOG.md +13 -0
  5. data/Gemfile +3 -0
  6. data/README.md +7 -2
  7. data/app/helpers/logux_helper.rb +1 -2
  8. data/config/routes.rb +1 -1
  9. data/lib/logux/{actions.rb → action.rb} +1 -1
  10. data/lib/logux/model/proxy.rb +1 -1
  11. data/lib/logux/model/updates_deprecator.rb +12 -8
  12. data/lib/logux/version.rb +1 -1
  13. data/lib/logux_rails.rb +22 -1
  14. data/lib/tasks/logux_tasks.rake +10 -37
  15. data/logux_rails.gemspec +3 -6
  16. metadata +14 -77
  17. data/app/controllers/logux_controller.rb +0 -41
  18. data/lib/logux.rb +0 -107
  19. data/lib/logux/action_caller.rb +0 -42
  20. data/lib/logux/action_controller.rb +0 -6
  21. data/lib/logux/add.rb +0 -37
  22. data/lib/logux/auth.rb +0 -6
  23. data/lib/logux/base_controller.rb +0 -37
  24. data/lib/logux/channel_controller.rb +0 -24
  25. data/lib/logux/class_finder.rb +0 -61
  26. data/lib/logux/client.rb +0 -21
  27. data/lib/logux/error_renderer.rb +0 -40
  28. data/lib/logux/meta.rb +0 -36
  29. data/lib/logux/node.rb +0 -37
  30. data/lib/logux/policy.rb +0 -14
  31. data/lib/logux/policy_caller.rb +0 -34
  32. data/lib/logux/process.rb +0 -9
  33. data/lib/logux/process/action.rb +0 -60
  34. data/lib/logux/process/auth.rb +0 -27
  35. data/lib/logux/process/batch.rb +0 -59
  36. data/lib/logux/response.rb +0 -18
  37. data/lib/logux/stream.rb +0 -25
  38. data/lib/logux/test.rb +0 -35
  39. data/lib/logux/test/helpers.rb +0 -75
  40. data/lib/logux/test/matchers.rb +0 -10
  41. data/lib/logux/test/matchers/base.rb +0 -25
  42. data/lib/logux/test/matchers/response_chunks.rb +0 -48
  43. data/lib/logux/test/matchers/send_to_logux.rb +0 -51
  44. data/lib/logux/test/store.rb +0 -21
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e2ddee267525e7f6503a6a64b42b4b18322dd7a597c1f535f5c3341921bad354
4
- data.tar.gz: b7f32ba3524a11d9a81872064231cc939773cc68a22029a3cf52e48253fafeb6
3
+ metadata.gz: 97f35ecf2895e15f1ca45d1ec4d4aec86108d8ffdb48e7ff112d06b5593a4477
4
+ data.tar.gz: '0568b3e3bad4592b33b0f5ecfd24ccbe4fb980ff8e037b30cc4bf0e2f12d9549'
5
5
  SHA512:
6
- metadata.gz: 5a82d8cf1df3c2c228b4e6a371cf027d146cb59bc67f338cbef4103745132047f56224024fa9b24347d5b3734ead07afe4d0ca744b0b7d8eef07fe3a246d8e38
7
- data.tar.gz: 7d9efeb074215bb2ac5c3d601ded5425f2c927efe5f6ed7c4f749c6f49b9f1fb33b4b40abdd0b9145912f1ecc17c08b3bca99580cd9f8a49fecbe2997a1869c3
6
+ metadata.gz: cf3aa01217dbf9d6175b7ad846d0c4da52df51b9a63f555ec0655c05e5016a5dea5a1c8126625533fce36a8eb45f4df4690f69fe3e2cf4928df6ac91fde2a52f
7
+ data.tar.gz: b105c769a9c97b363da83f6deba35ba7cd026a5b0eb70a780e1936c9c51d6c64465de295c9d32aab977e80d0373b7755e2eece5503610c4d579c92a3f7459b5d
@@ -1,3 +1,4 @@
1
+ language: minimal
1
2
  sudo: require
2
3
  services:
3
4
  - docker
data/Appraisals CHANGED
@@ -11,3 +11,7 @@ end
11
11
  appraise '5.2' do
12
12
  gem 'activerecord', '~> 5.2'
13
13
  end
14
+
15
+ appraise '6.0' do
16
+ gem 'activerecord', '~> 6.0'
17
+ end
@@ -0,0 +1,13 @@
1
+ # Change Log
2
+ This project adheres to [Semantic Versioning](http://semver.org/).
3
+
4
+ ## 0.2
5
+ * Core Logux facilities are moved to `logux-rack` gem.
6
+ * `Logux::Actions` is soft-deprecated. Please use `Logux::Action` from now on.
7
+ * `Logux::Model::UpdatesDeprecator` is now coupled with `Logux::ActionCaller` via Logux configuration.
8
+
9
+ ## 0.1.1
10
+ * Rails 6.0 support.
11
+
12
+ ## 0.1
13
+ * Initial release.
data/Gemfile CHANGED
@@ -6,3 +6,6 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
6
 
7
7
  # Specify your gem's dependencies in logux_rails.gemspec
8
8
  gemspec
9
+
10
+ # NOTE: Remove this line after logux-rack is released on rubygems
11
+ gem 'logux-rack', github: 'logux/logux-rack'
data/README.md CHANGED
@@ -30,17 +30,22 @@ Logux.configuration do |config|
30
30
  end
31
31
  ```
32
32
 
33
- Mount logux in routes:
33
+ Mount `Logux::Rack` in your application routing configuration:
34
34
 
35
35
  ```ruby
36
+ # config/routes.rb
37
+ Rails.application.routes.draw do
36
38
  mount Logux::Engine => '/'
39
+ end
37
40
  ```
38
41
 
39
42
  After this, POST requests to `/logux` will be processed by `LoguxController`. You can redefine it or inherit from, if it necessary, for example, for implementing custom authorization flow.
40
43
 
41
44
  Logux Rails will try to find Action for the specific message from Logux Server. For example, for `project/rename` action, you should define `Action::Project` class, inherited from `Logux::Action` base class, and implement `rename` method.
42
45
 
43
- You can execute `rake logux:actions` to get the list of available action types, or `rake logux:channels` to get the list of available channels.
46
+ ### Rake commands
47
+
48
+ Use `rails logux:actions` command to get the list of available action types, or `rails logux:channels` for channels. The default search path is set to `app/logux/actions` and `app/logux/channels` for actions and channels correspondingly, assuming `app` directory is the root of your Rails application. Both command support custom search paths: `rails logux:actions[lib/logux/actions]`.
44
49
 
45
50
  ## Development with Docker
46
51
 
@@ -1,4 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module LoguxHelper
4
- end
3
+ module LoguxHelper; end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  Logux::Engine.routes.draw do
4
- resource :logux, only: %i[create], controller: :logux
4
+ mount Logux::Rack::App => '/'
5
5
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Logux
4
- class Actions < ::ActionController::Parameters
4
+ class Action < ::ActionController::Parameters
5
5
  def action_name
6
6
  type&.split('/')&.dig(0)
7
7
  end
@@ -13,7 +13,7 @@ module Logux
13
13
  logux_order: meta.logux_order,
14
14
  attributes: attributes
15
15
  )
16
- @model.update_attributes(updater.updated_attributes)
16
+ @model.update(updater.updated_attributes)
17
17
  end
18
18
 
19
19
  def updated_at(field)
@@ -5,17 +5,15 @@ module Logux
5
5
  class UpdatesDeprecator
6
6
  EVENT = 'logux.insecure_update'
7
7
 
8
- class << self
9
- def watch(args = {}, &block)
10
- new(args).watch(&block)
11
- end
8
+ def self.call(options = {}, &block)
9
+ new(options).call(&block)
12
10
  end
13
11
 
14
- def initialize(level: :warn)
15
- @level = level
12
+ def initialize(options)
13
+ @options = options
16
14
  end
17
15
 
18
- def watch(&block)
16
+ def call(&block)
19
17
  callback = lambda(&method(:handle_insecure_update))
20
18
  ActiveSupport::Notifications.subscribed(callback, EVENT, &block)
21
19
  end
@@ -42,13 +40,19 @@ module Logux
42
40
  Logux tracked #{pluralized_attributes} (#{insecure_attributes.join(', ')}) should be updated using model.logux.update(...)
43
41
  TEXT
44
42
 
45
- case @level
43
+ case level
46
44
  when :warn
47
45
  ActiveSupport::Deprecation.warn(message)
48
46
  when :error
49
47
  raise InsecureUpdateError, message
50
48
  end
51
49
  end
50
+
51
+ DEFAULT_LEVEL = :warn
52
+
53
+ def level
54
+ @options[:level] || DEFAULT_LEVEL
55
+ end
52
56
  end
53
57
  end
54
58
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Logux
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
@@ -1,3 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'logux'
3
+ require 'action_controller'
4
+ require 'active_support'
5
+ require 'logux/rack'
6
+ require 'rails/engine'
7
+ require 'logux/engine'
8
+
9
+ module Logux
10
+ autoload :Model, 'logux/model'
11
+
12
+ configurable %i[
13
+ action_watcher
14
+ action_watcher_options
15
+ ]
16
+
17
+ configuration_defaults do |config|
18
+ config.action_watcher = Logux::Model::UpdatesDeprecator
19
+ config.action_watcher_options = { level: :error }
20
+ config.logger = Rails.logger if defined?(Rails.logger)
21
+ config.logger ||= ActiveSupport::Logger.new(STDOUT)
22
+ config.on_error = proc {}
23
+ end
24
+ end
@@ -1,46 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # rubocop:disable Metrics/BlockLength
4
- namespace :logux do
5
- desc 'Lists all Logux action types'
6
- task actions: :environment do
7
- Dir[Rails.root.join('app', 'logux', 'actions', '**', '*.rb')].each do |file|
8
- require file
9
- end
3
+ require 'logux/rake_tasks'
10
4
 
11
- output = [%w[action.type Class#method]]
12
- Logux::ActionController.descendants.sort_by(&:name).each do |klass|
13
- klass.instance_methods(false).sort.each do |action|
14
- output << [
15
- "#{klass.name.gsub(/^Actions::/, '').underscore}/#{action}",
16
- "#{klass.name}##{action}"
17
- ]
18
- end
19
- end
5
+ module Logux
6
+ class RakeTasks
7
+ protected
20
8
 
21
- first_column_length = output.map(&:first).max_by(&:length).length
22
- output.each do |action, klass_name|
23
- puts "#{action.rjust(first_column_length, ' ')} #{klass_name}"
9
+ def default_actions_path
10
+ ::Rails.root.join('app', 'logux', 'actions')
24
11
  end
25
- end
26
-
27
- desc 'Lists all Logux channels'
28
- task channels: :environment do
29
- path = Rails.root.join('app', 'logux', 'channels', '**', '*.rb')
30
- Dir[path].each { |file| require file }
31
12
 
32
- output = [%w[channel Class]]
33
- Logux::ChannelController.descendants.map(&:name).sort.each do |klass_name|
34
- output << [
35
- klass_name.gsub(/^Channels::/, '').underscore,
36
- klass_name
37
- ]
38
- end
39
-
40
- first_column_length = output.map(&:first).max_by(&:length).length
41
- output.each do |channel, klass_name|
42
- puts "#{channel.rjust(first_column_length, ' ')} #{klass_name}"
13
+ def default_channels_path
14
+ ::Rails.root.join('app', 'logux', 'channels')
43
15
  end
44
16
  end
45
17
  end
46
- # rubocop:enable Metrics/BlockLength
18
+
19
+ Logux::RakeTasks.new
@@ -22,14 +22,11 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ['lib']
24
24
 
25
- spec.add_dependency 'colorize'
26
- spec.add_dependency 'configurations'
27
- spec.add_dependency 'nanoid'
28
- spec.add_dependency 'rails', '>= 5.0'
29
- spec.add_dependency 'rest-client'
25
+ spec.add_dependency 'logux-rack', '>= 0.1.0'
26
+ spec.add_dependency 'rails', '>= 5.0', '< 6.1'
30
27
  spec.add_development_dependency 'appraisal', '~> 2.2'
31
28
  spec.add_development_dependency 'bundler', '~> 1.16'
32
- spec.add_development_dependency 'combustion', '~> 1.0.0'
29
+ spec.add_development_dependency 'combustion', '~> 1.1.0'
33
30
  spec.add_development_dependency 'coveralls'
34
31
  spec.add_development_dependency 'factory_bot'
35
32
  spec.add_development_dependency 'pg'
metadata CHANGED
@@ -1,57 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logux_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - WildDima
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-07-09 00:00:00.000000000 Z
11
+ date: 2019-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: colorize
14
+ name: logux-rack
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 0.1.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: configurations
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: nanoid
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
26
+ version: 0.1.0
55
27
  - !ruby/object:Gem::Dependency
56
28
  name: rails
57
29
  requirement: !ruby/object:Gem::Requirement
@@ -59,6 +31,9 @@ dependencies:
59
31
  - - ">="
60
32
  - !ruby/object:Gem::Version
61
33
  version: '5.0'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '6.1'
62
37
  type: :runtime
63
38
  prerelease: false
64
39
  version_requirements: !ruby/object:Gem::Requirement
@@ -66,20 +41,9 @@ dependencies:
66
41
  - - ">="
67
42
  - !ruby/object:Gem::Version
68
43
  version: '5.0'
69
- - !ruby/object:Gem::Dependency
70
- name: rest-client
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :runtime
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
44
+ - - "<"
81
45
  - !ruby/object:Gem::Version
82
- version: '0'
46
+ version: '6.1'
83
47
  - !ruby/object:Gem::Dependency
84
48
  name: appraisal
85
49
  requirement: !ruby/object:Gem::Requirement
@@ -114,14 +78,14 @@ dependencies:
114
78
  requirements:
115
79
  - - "~>"
116
80
  - !ruby/object:Gem::Version
117
- version: 1.0.0
81
+ version: 1.1.0
118
82
  type: :development
119
83
  prerelease: false
120
84
  version_requirements: !ruby/object:Gem::Requirement
121
85
  requirements:
122
86
  - - "~>"
123
87
  - !ruby/object:Gem::Version
124
- version: 1.0.0
88
+ version: 1.1.0
125
89
  - !ruby/object:Gem::Dependency
126
90
  name: coveralls
127
91
  requirement: !ruby/object:Gem::Requirement
@@ -318,11 +282,11 @@ files:
318
282
  - ".rubocop_todo.yml"
319
283
  - ".travis.yml"
320
284
  - Appraisals
285
+ - CHANGELOG.md
321
286
  - Gemfile
322
287
  - LICENSE.txt
323
288
  - README.md
324
289
  - Rakefile
325
- - app/controllers/logux_controller.rb
326
290
  - app/helpers/logux_helper.rb
327
291
  - app/logux/actions.rb
328
292
  - app/logux/policies.rb
@@ -333,40 +297,13 @@ files:
333
297
  - lib/generators/logux/model/USAGE
334
298
  - lib/generators/logux/model/model_generator.rb
335
299
  - lib/generators/logux/model/templates/migration.rb.erb
336
- - lib/logux.rb
337
- - lib/logux/action_caller.rb
338
- - lib/logux/action_controller.rb
339
- - lib/logux/actions.rb
340
- - lib/logux/add.rb
341
- - lib/logux/auth.rb
342
- - lib/logux/base_controller.rb
343
- - lib/logux/channel_controller.rb
344
- - lib/logux/class_finder.rb
345
- - lib/logux/client.rb
300
+ - lib/logux/action.rb
346
301
  - lib/logux/engine.rb
347
- - lib/logux/error_renderer.rb
348
- - lib/logux/meta.rb
349
302
  - lib/logux/model.rb
350
303
  - lib/logux/model/dsl.rb
351
304
  - lib/logux/model/proxy.rb
352
305
  - lib/logux/model/updater.rb
353
306
  - lib/logux/model/updates_deprecator.rb
354
- - lib/logux/node.rb
355
- - lib/logux/policy.rb
356
- - lib/logux/policy_caller.rb
357
- - lib/logux/process.rb
358
- - lib/logux/process/action.rb
359
- - lib/logux/process/auth.rb
360
- - lib/logux/process/batch.rb
361
- - lib/logux/response.rb
362
- - lib/logux/stream.rb
363
- - lib/logux/test.rb
364
- - lib/logux/test/helpers.rb
365
- - lib/logux/test/matchers.rb
366
- - lib/logux/test/matchers/base.rb
367
- - lib/logux/test/matchers/response_chunks.rb
368
- - lib/logux/test/matchers/send_to_logux.rb
369
- - lib/logux/test/store.rb
370
307
  - lib/logux/version.rb
371
308
  - lib/logux_rails.rb
372
309
  - lib/tasks/logux_tasks.rake
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class LoguxController < ActionController::Base
4
- include ActionController::Live
5
-
6
- def create
7
- logux_stream.write('[')
8
- Logux.verify_request_meta_data(meta_params)
9
- Logux.process_batch(stream: logux_stream, batch: command_params)
10
- rescue => ex
11
- handle_processing_errors(ex)
12
- ensure
13
- logux_stream.write(']')
14
- logux_stream.close
15
- end
16
-
17
- private
18
-
19
- def unsafe_params
20
- params.to_unsafe_h
21
- end
22
-
23
- def command_params
24
- unsafe_params.dig('commands')
25
- end
26
-
27
- def meta_params
28
- unsafe_params&.slice(:version, :password)
29
- end
30
-
31
- def logux_stream
32
- @logux_stream ||= Logux::Stream.new(response.stream)
33
- end
34
-
35
- def handle_processing_errors(exception)
36
- Logux.configuration.on_error.call(exception)
37
- Logux.logger.error("#{exception}\n#{exception.backtrace.join("\n")}")
38
- ensure
39
- logux_stream.write(Logux::ErrorRenderer.new(exception).message)
40
- end
41
- end