intercept 0.1.0 → 0.2.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: 65efc6449e64770b9e8e4fc660e3ca5f2ff6944a6dffb98de6fb9c57f6e1bc38
4
- data.tar.gz: 487e479414bd01699d4931b69295551f9e117f0a0a9195c84887f4856260c760
3
+ metadata.gz: b8545ab8342d8437069c4f8bae1096cc88a541932086c29a1a697fc5ddf53bd1
4
+ data.tar.gz: c72134e33df3909b77734d554c68c7ee3db58f037a04ef3bd1b4f7fcc7847eb0
5
5
  SHA512:
6
- metadata.gz: 182782a85baf8ee54d6977512a25b9bc949d08c03de5d2a39cea00d6bcb9d02d6fe0bba2d894061bfb6079ee8dfb6cc8baacd0a818eb20f993ce1e4bfdd96c19
7
- data.tar.gz: a60e30b42b9f8ca96c89d80da8f928cae6229f6bc1a699f5d0eb744c04c354abc36e1be8c63737d0ecb387f7176ec9bd0067acfed1a166aa4cac61297a4e00e0
6
+ metadata.gz: 215018d5e8bce4ee3bc2e49b733a28b92803bb747947ff44b3e95fe3e73a899ad1c7691a4fa274df44188d19678119c0e1b46568c6f65c3e3fa90a4e049fb9ea
7
+ data.tar.gz: f346a8deedd06161621330767bded0b3858d5ba07bc2742eb19a4ed0c2cd92694fb14d7258bdae50835880525e58b74201e91172da75d1b71d0ce7259d34e113
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Intercept
2
4
  module Strategy
3
5
  class Mapper
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Intercept
2
4
  module Strategy
3
5
  class Replace
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Intercept
2
4
  module Strategy
3
5
  class WhiteList
@@ -1,3 +1,3 @@
1
1
  module Intercept
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -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 Builder
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 != 'delivering_message' && registration_method != :delivering_message
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
- def delivering_message(message)
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
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'intercept/version'
2
- require 'intercept/builder'
4
+ require 'intercept/worker'
3
5
 
4
6
  module Intercept
5
7
 
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.1.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