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 +4 -4
- data/app/controllers/two_percent/application_controller.rb +5 -0
- data/app/controllers/two_percent/bulk_controller.rb +17 -0
- data/app/controllers/two_percent/scim_controller.rb +0 -6
- data/config/routes.rb +1 -0
- data/lib/two_percent/bulk_processor.rb +25 -0
- data/lib/two_percent/event_handler.rb +26 -0
- data/lib/two_percent/version.rb +1 -1
- data/lib/two_percent.rb +2 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2d0acb208269634fee03c154461267e688d576daa63bbb2322980b607e06dc4
|
4
|
+
data.tar.gz: 84ef35de29b51d79a26bd7f217b78c3540e8111f34694066a1fdceb00bdd5aea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3485e3207a1fd5070ac6d392c02d121d597d5adab67eaf318f16c2f2ea7205fbcd54afd81da6b9ed823b0a4133868c30bc1e3e43fb98d06806ea4ccd3df747e
|
7
|
+
data.tar.gz: 17c3b0c0d90d6c3f94f9d218a0381e00d42f83bab17183b2d62b4e17adca69e89edd726204d5f326e9ecf70d79981a30a23bf9914eccd68f900297f306319e61
|
@@ -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
@@ -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
|
data/lib/two_percent/version.rb
CHANGED
data/lib/two_percent.rb
CHANGED
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.
|
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-
|
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.
|
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
|