intercept 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8545ab8342d8437069c4f8bae1096cc88a541932086c29a1a697fc5ddf53bd1
|
4
|
+
data.tar.gz: c72134e33df3909b77734d554c68c7ee3db58f037a04ef3bd1b4f7fcc7847eb0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 215018d5e8bce4ee3bc2e49b733a28b92803bb747947ff44b3e95fe3e73a899ad1c7691a4fa274df44188d19678119c0e1b46568c6f65c3e3fa90a4e049fb9ea
|
7
|
+
data.tar.gz: f346a8deedd06161621330767bded0b3858d5ba07bc2742eb19a4ed0c2cd92694fb14d7258bdae50835880525e58b74201e91172da75d1b71d0ce7259d34e113
|
data/lib/intercept/version.rb
CHANGED
@@ -1,21 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'intercept/strategy/replace'
|
2
4
|
require 'intercept/strategy/mapper'
|
3
5
|
require 'intercept/strategy/white_list'
|
4
6
|
|
5
7
|
module Intercept
|
6
|
-
class
|
8
|
+
# Base class of the intercept module.
|
9
|
+
# A worker object is responsible to intercept and modify state of registering class's objects
|
10
|
+
class Worker
|
7
11
|
attr_reader :interceptor_map, :decorator_map
|
8
12
|
|
13
|
+
# @param registration_method [String, Symbol] method_name which is called by the registering class.
|
14
|
+
# @param interceptor_map [Hash] Keys represent fields to be modified. Values are Strategy class object
|
15
|
+
# @param decorator_map [Hash] Keys represent fields to be modified. Values are Decorator class object
|
9
16
|
def initialize(registration_method, interceptor_map = {}, decorator_map = {})
|
10
17
|
@interceptor_map = interceptor_map
|
11
18
|
@decorator_map = decorator_map
|
12
19
|
|
13
|
-
if registration_method != '
|
20
|
+
if registration_method != 'intercept' && registration_method != :intercept
|
14
21
|
define_singleton_method(registration_method) { |message| delivering_message(message) }
|
15
22
|
end
|
16
23
|
end
|
17
24
|
|
18
|
-
|
25
|
+
# This method is called when we want to intercept and modify an object.
|
26
|
+
# 'registration_method' parameter of initialize is an alias to this method.
|
27
|
+
# @param message is an object of any registering class
|
28
|
+
def intercept(message)
|
19
29
|
interceptor_map.each do |field, strategy|
|
20
30
|
if message.respond_to?(field) && message.respond_to?("#{field}=")
|
21
31
|
message.public_send("#{field}=", strategy.process_identities(message.public_send field))
|
data/lib/intercept.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: intercept
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gemin Patel
|
@@ -71,11 +71,11 @@ files:
|
|
71
71
|
- bin/setup
|
72
72
|
- intercept.gemspec
|
73
73
|
- lib/intercept.rb
|
74
|
-
- lib/intercept/builder.rb
|
75
74
|
- lib/intercept/strategy/mapper.rb
|
76
75
|
- lib/intercept/strategy/replace.rb
|
77
76
|
- lib/intercept/strategy/white_list.rb
|
78
77
|
- lib/intercept/version.rb
|
78
|
+
- lib/intercept/worker.rb
|
79
79
|
- spec/intercept_spec.rb
|
80
80
|
- spec/spec_helper.rb
|
81
81
|
homepage: https://github.com/GeminPatel/intercept
|