two_percent 0.2.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: 3141327371c4843aa100b88da07804dbb16aaafe4f80315a9a68bcda88ef7b80
4
- data.tar.gz: d7fb152e1cb4b68c3ae763ccd9e641cf159447acf1e299e4bbf316496a11cade
3
+ metadata.gz: d2d0acb208269634fee03c154461267e688d576daa63bbb2322980b607e06dc4
4
+ data.tar.gz: 84ef35de29b51d79a26bd7f217b78c3540e8111f34694066a1fdceb00bdd5aea
5
5
  SHA512:
6
- metadata.gz: 27d1a9e34f7e1527052c169769786203c4284282e7d79241d4008adf64aaae567879d8d3d441bb9d842d884b5f5a771b89e3bedd08ce779b8c5e18ebe9b804f6
7
- data.tar.gz: a3a7e6d5bbbbe602008ddc0b1096a643999c676bcd14849403bd3e636fca996e3bf84285e81c742806fe90f6556f86a628b4af5ab8e39a7d0cf99cca0fda51b1
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
 
@@ -31,11 +29,7 @@ module TwoPercent
31
29
  private
32
30
 
33
31
  def scim_params
34
- params.except(:controller, :action, :resource_type, :id).as_json.deep_symbolize_keys
35
- end
36
-
37
- def authenticate
38
- instance_exec(&TwoPercent.config.authenticate)
32
+ params.except(:controller, :action, :resource_type).as_json.deep_symbolize_keys
39
33
  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.2.0"
4
+ VERSION = "0.4.0"
5
5
  end
data/lib/two_percent.rb CHANGED
@@ -4,7 +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
- # Your code goes here...
10
11
  end
metadata CHANGED
@@ -1,17 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: two_percent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carlos Palhares
8
8
  - Katie Edgar
9
9
  - Dan Smith
10
- - Denis Zablotskii
11
10
  autorequire:
12
11
  bindir: bin
13
12
  cert_chain: []
14
- date: 2025-03-27 00:00:00.000000000 Z
13
+ date: 2025-05-15 00:00:00.000000000 Z
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
16
  name: aether_observatory
@@ -45,9 +44,8 @@ description: Adds a thin SCIM interface, and delegates the actions taken on writ
45
44
  calls to observers
46
45
  email:
47
46
  - carlos.palhares@powerhrg.com
48
- - katie.edgar@powerhrg.com
47
+ - katie.weber@powerhrg.com
49
48
  - dsmith@powerhrg.com
50
- - denis.zablotskii@powerhrg.com
51
49
  executables: []
52
50
  extensions: []
53
51
  extra_rdoc_files: []
@@ -55,6 +53,7 @@ files:
55
53
  - MIT-LICENSE
56
54
  - Rakefile
57
55
  - app/controllers/two_percent/application_controller.rb
56
+ - app/controllers/two_percent/bulk_controller.rb
58
57
  - app/controllers/two_percent/scim_controller.rb
59
58
  - app/events/two_percent/application_event.rb
60
59
  - app/events/two_percent/create_event.rb
@@ -64,8 +63,10 @@ files:
64
63
  - config/routes.rb
65
64
  - lib/tasks/two_percent_tasks.rake
66
65
  - lib/two_percent.rb
66
+ - lib/two_percent/bulk_processor.rb
67
67
  - lib/two_percent/configuration.rb
68
68
  - lib/two_percent/engine.rb
69
+ - lib/two_percent/event_handler.rb
69
70
  - lib/two_percent/version.rb
70
71
  homepage: https://github.com/powerhome/power-tools
71
72
  licenses:
@@ -90,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
91
  - !ruby/object:Gem::Version
91
92
  version: '0'
92
93
  requirements: []
93
- rubygems_version: 3.5.22
94
+ rubygems_version: 3.5.16
94
95
  signing_key:
95
96
  specification_version: 4
96
97
  summary: Adds a thin SCIM interface, and delegates the actions taken on write calls