carb-container 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
  SHA1:
3
- metadata.gz: 95c46b2436f16825eb22774536485297b23ad8ba
4
- data.tar.gz: 60f675251e578ea250cae6f2f47e16e8194714d0
3
+ metadata.gz: 4b2266086979fc001d37b802f0737e46a0101fa7
4
+ data.tar.gz: 85fe087f9b35d32ee015b897f3eeba8f6a670a3e
5
5
  SHA512:
6
- metadata.gz: aa4c49159f53467cff172a8dd54214c702ebaa4b7987f9d015c611c3483f09dc60775debe3406ce22099b54fb4edcef58d0c86c3ba5ed8d7b3a9224bedeb1418
7
- data.tar.gz: c32e3f6ef95c1ca332e58a802aeb67415f1631a31b5800c98f73b922117e94dc8bfa1f6a0f12a917d35672df056e9907c2c67acbe59641bd940d293600b82a46
6
+ metadata.gz: 3fe8e15f66cae9431cec660c5cbd082e13c5394d5a6c619dc99ccff405ff702ef206acc6f7e94770e0b10ab3e34e4c866f786b45c53f2a7acdf4421cd729f489
7
+ data.tar.gz: 0353b4d1bb150e98b3a8815f62e1585b7cd0d41523ace337c6778f0764255d95c3f20dbbe6a66d02e5ccb22605af1adeec1278c66efd000b80a4df8b2135eff7
data/README.md CHANGED
@@ -61,9 +61,9 @@ container[:my_class].new.hello
61
61
 
62
62
  ### Carb::Container::RegistrationGlue
63
63
 
64
- A utility class that allows you to create a class method inside `Class` so that
65
- you can easily register any newly created class. This is entirely optional, for
66
- people who don't like monkey patching, can be skipped.
64
+ A utility class that allows you to create a class method inside `Module` so
65
+ that you can easily register any newly created class. This is entirely
66
+ optional, for people who don't like monkey patching, can be skipped.
67
67
 
68
68
  ```ruby
69
69
  MyContainer = Carb::Container::RegistryContainer.new
data/bin/console CHANGED
@@ -6,9 +6,5 @@ require "carb/container"
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
8
8
 
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
9
+ require "pry"
10
+ Pry.start(__FILE__)
@@ -17,18 +17,18 @@ module Carb::Container
17
17
  def initialize(container, converter: ClassNameToMethodName.new)
18
18
  @container = container
19
19
  @converter = converter
20
+ def_carb_container(container, converter)
20
21
  end
21
22
 
22
- def included(klass)
23
- # Required for scope purposes
24
- kontainer = container
25
- convert = converter
23
+ private
26
24
 
27
- klass.define_singleton_method(:carb_container) do |as: nil|
25
+ def def_carb_container(kontainer, convert)
26
+ define_method(:carb_container) do |as: nil|
28
27
  as ||= convert.call(self.name.to_s)
29
28
  as = as.to_sym
30
29
  kontainer.register(as, -> { self })
31
30
  end
31
+ send(:protected, :carb_container)
32
32
  end
33
33
  end
34
34
  end
@@ -10,8 +10,9 @@ module Carb::Container
10
10
  # @param container [#register] a generic object, usually a
11
11
  # {RegistryContainer} which responds to `#register(name, dependency)`,
12
12
  # it's the only required argument
13
- # @param target [Object] class where you want to add the class method
14
- # `carb_container`. Usually it's {::Class} itself
13
+ # @param target [Class, Module] class where you want to add the class
14
+ # method `carb_container`. Usually it's the {::Module} class so it's
15
+ # available on all classes
15
16
  # @param registerer [Module] subclass of a module which can be included.
16
17
  # Usually it's {Registerer} which is an internal module used to store
17
18
  # objects inside a container which responds to `#register`
@@ -20,11 +21,30 @@ module Carb::Container
20
21
  # name. By default it uses an instance of {ClassNameToMethodName}
21
22
  def call(
22
23
  container,
23
- target: Class,
24
+ target: Module,
24
25
  registerer: Registerer,
25
26
  converter: ClassNameToMethodName.new
26
27
  )
27
- target.send(:include, registerer.new(container, converter: converter))
28
+ registerer_instance = registerer.new(container, converter: converter)
29
+
30
+ include_registerer(target, registerer_instance)
31
+ end
32
+
33
+ private
34
+
35
+ def perform_include(target, includer, registerer)
36
+ target.send(includer, registerer)
37
+ end
38
+
39
+ def include_registerer(target, registerer)
40
+ includer = inclusion_method(target)
41
+
42
+ perform_include(target, includer, registerer)
43
+ end
44
+
45
+ def inclusion_method(target)
46
+ return :include if target <= Module
47
+ :extend
28
48
  end
29
49
 
30
50
  class << self
@@ -1,5 +1,5 @@
1
1
  module Carb
2
2
  module Container
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carb-container
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
  - Fire-Dragon-DoL
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-24 00:00:00.000000000 Z
11
+ date: 2017-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: carb-core