two_percent 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9c5a241a697109d794c29fbac31f4ecd363b883dd70f0a2d22bec5a94bdccb98
4
- data.tar.gz: 539239a87f4b1ca23c84b7d3080db2104db74fa09a2f906a41b3cac168e7c91b
3
+ metadata.gz: d2d0acb208269634fee03c154461267e688d576daa63bbb2322980b607e06dc4
4
+ data.tar.gz: 84ef35de29b51d79a26bd7f217b78c3540e8111f34694066a1fdceb00bdd5aea
5
5
  SHA512:
6
- metadata.gz: 470b871f02fb8a5d125fb80c371186fe0301b69293b4e8a00ac9353906c8287f137b33310feee56f32c936faf5215e8801f83ed0cb72c9cbd1b5e3de4c7c4c10
7
- data.tar.gz: 9b4957e2a180f5ae6c1fc8314138b134d6b219997ec754846d3296920efe84f00981ab555f494608428f03adab1bf2dff4d35cd8ce56758c61a1bd4050ecec83
6
+ metadata.gz: e3485e3207a1fd5070ac6d392c02d121d597d5adab67eaf318f16c2f2ea7205fbcd54afd81da6b9ed823b0a4133868c30bc1e3e43fb98d06806ea4ccd3df747e
7
+ data.tar.gz: 17c3b0c0d90d6c3f94f9d218a0381e00d42f83bab17183b2d62b4e17adca69e89edd726204d5f326e9ecf70d79981a30a23bf9914eccd68f900297f306319e61
@@ -2,5 +2,10 @@
2
2
 
3
3
  module TwoPercent
4
4
  class ApplicationController < ActionController::API
5
+ before_action :authenticate
6
+
7
+ def authenticate
8
+ instance_exec(&TwoPercent.config.authenticate)
9
+ end
5
10
  end
6
11
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwoPercent
4
+ class BulkController < ApplicationController
5
+ def _dispatch = processor.dispatch
6
+
7
+ private
8
+
9
+ def processor
10
+ @processor ||= TwoPercent::BulkProcessor.new(operations)
11
+ end
12
+
13
+ def operations
14
+ params.require(:Operations).map { _1.permit(:method, :path, :bulkId, data: {}).to_h }
15
+ end
16
+ end
17
+ end
@@ -2,8 +2,6 @@
2
2
 
3
3
  module TwoPercent
4
4
  class ScimController < ApplicationController
5
- before_action :authenticate
6
-
7
5
  def create
8
6
  TwoPercent::CreateEvent.create(resource: params[:resource_type], params: scim_params)
9
7
 
@@ -33,9 +31,5 @@ module TwoPercent
33
31
  def scim_params
34
32
  params.except(:controller, :action, :resource_type).as_json.deep_symbolize_keys
35
33
  end
36
-
37
- def authenticate
38
- instance_exec(&TwoPercent.config.authenticate)
39
- end
40
34
  end
41
35
  end
data/config/routes.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  TwoPercent::Engine.routes.draw do
4
+ post "/Bulk" => "bulk#_dispatch"
4
5
  post "/:resource_type" => "scim#create"
5
6
  patch "/:resource_type/:id" => "scim#update"
6
7
  put "/:resource_type/:id" => "scim#replace"
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwoPercent
4
+ class BulkProcessor
5
+ def initialize(operations)
6
+ @operations = operations
7
+ end
8
+
9
+ def dispatch(event_handler = EventHandler)
10
+ @operations.each do |operation|
11
+ resource, id = parse_path(operation[:path])
12
+ attrs = { resource: resource, id: id, params: operation[:data] }.compact
13
+ event_handler.dispatch(operation[:method], **attrs)
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def parse_path(path)
20
+ _, resource_type, id = path.split("/")
21
+
22
+ [resource_type, id]
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwoPercent
4
+ class EventHandler
5
+ def self.dispatch(method, **attrs)
6
+ EventHandler.new(method).dispatch(**attrs)
7
+ end
8
+
9
+ METHOD_EVENT = {
10
+ "POST" => "TwoPercent::CreateEvent",
11
+ "PATCH" => "TwoPercent::UpdateEvent",
12
+ "PUT" => "TwoPercent::ReplaceEvent",
13
+ "DELETE" => "TwoPercent::DeleteEvent",
14
+ }.freeze
15
+
16
+ def initialize(method)
17
+ @event = METHOD_EVENT.fetch(method) do
18
+ raise "Invalid method #{method}"
19
+ end.constantize
20
+ end
21
+
22
+ def dispatch(**attrs)
23
+ @event.create(**attrs)
24
+ end
25
+ end
26
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TwoPercent
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
data/lib/two_percent.rb CHANGED
@@ -4,6 +4,8 @@ require "aether_observatory"
4
4
 
5
5
  require "two_percent/version"
6
6
  require "two_percent/configuration"
7
+ require "two_percent/event_handler"
8
+ require "two_percent/bulk_processor"
7
9
 
8
10
  module TwoPercent
9
11
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: two_percent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carlos Palhares
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2025-05-07 00:00:00.000000000 Z
13
+ date: 2025-05-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: aether_observatory
@@ -53,6 +53,7 @@ files:
53
53
  - MIT-LICENSE
54
54
  - Rakefile
55
55
  - app/controllers/two_percent/application_controller.rb
56
+ - app/controllers/two_percent/bulk_controller.rb
56
57
  - app/controllers/two_percent/scim_controller.rb
57
58
  - app/events/two_percent/application_event.rb
58
59
  - app/events/two_percent/create_event.rb
@@ -62,8 +63,10 @@ files:
62
63
  - config/routes.rb
63
64
  - lib/tasks/two_percent_tasks.rake
64
65
  - lib/two_percent.rb
66
+ - lib/two_percent/bulk_processor.rb
65
67
  - lib/two_percent/configuration.rb
66
68
  - lib/two_percent/engine.rb
69
+ - lib/two_percent/event_handler.rb
67
70
  - lib/two_percent/version.rb
68
71
  homepage: https://github.com/powerhome/power-tools
69
72
  licenses:
@@ -88,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
91
  - !ruby/object:Gem::Version
89
92
  version: '0'
90
93
  requirements: []
91
- rubygems_version: 3.5.22
94
+ rubygems_version: 3.5.16
92
95
  signing_key:
93
96
  specification_version: 4
94
97
  summary: Adds a thin SCIM interface, and delegates the actions taken on write calls