ioc_rb 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a5330611b991eea6ce2b181af7e34bbbb6e9eedc
4
+ data.tar.gz: 5e576b65af18fe9f1e1e043b86e2ebbffc9e33fc
5
+ SHA512:
6
+ metadata.gz: 3644f68a28d35e52c2572aa79d66de7b81f70c6e54e4906402e55f0e073da5a1cf70af3f85fa171df16f0f1075b67b013195483d4ba558959f8f382896d1a4c5
7
+ data.tar.gz: 946474ccb665a536448031cdd12ea9e1c922bc0ff5c25dbe215e444fd77798d5c7f52348243688dedf22f9ea323c540e5a6c0e8916d3f4bf471e48aa93e6d54e
data/Gemfile CHANGED
@@ -5,5 +5,4 @@ gemspec
5
5
 
6
6
  group :test do
7
7
  gem 'rspec'
8
- gem 'debugger'
9
8
  end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ioc_rb (0.1.1)
4
+ ioc_rb (0.2.0)
5
5
  activesupport
6
6
  request_store
7
7
 
@@ -15,13 +15,6 @@ GEM
15
15
  thread_safe (~> 0.1)
16
16
  tzinfo (~> 0.3.37)
17
17
  atomic (1.1.14)
18
- columnize (0.3.6)
19
- debugger (1.6.5)
20
- columnize (>= 0.3.1)
21
- debugger-linecache (~> 1.2.0)
22
- debugger-ruby_core_source (~> 1.3.1)
23
- debugger-linecache (1.2.0)
24
- debugger-ruby_core_source (1.3.1)
25
18
  diff-lcs (1.2.5)
26
19
  i18n (0.6.9)
27
20
  minitest (4.7.5)
@@ -45,7 +38,6 @@ PLATFORMS
45
38
 
46
39
  DEPENDENCIES
47
40
  bundler (~> 1.3)
48
- debugger
49
41
  ioc_rb!
50
42
  rake
51
43
  rspec
data/README.md CHANGED
@@ -92,3 +92,6 @@ Or install it yourself as:
92
92
  1. Constructor based injection
93
93
  2. Scope registration, refactor BeanFactory. IocRb:Container.register_scope(SomeScope)
94
94
  3. Write documentation with more examples
95
+
96
+ ## Author
97
+ Albert Gazizov, [@deeper4k](https://twitter.com/deeper4k)
data/ioc_rb.gemspec CHANGED
@@ -6,8 +6,8 @@ require 'ioc_rb/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "ioc_rb"
8
8
  spec.version = IocRb::VERSION
9
- spec.authors = ["Albert Gazizov", "Ruslan Gatiyatov"]
10
- spec.email = ["deeper4k@gmail.com", "ruslan.gatiyatov@gmail.com"]
9
+ spec.authors = ["Albert Gazizov"]
10
+ spec.email = ["deeper4k@gmail.com"]
11
11
  spec.description = %q{Inversion of Controll Container}
12
12
  spec.summary = %q{Inversion of Controll Container}
13
13
  spec.homepage = "http://github.com/deeper4k/ioc_rb"
@@ -5,10 +5,12 @@ require 'ioc_rb/scopes/request_scope'
5
5
 
6
6
  # Instantiates beans according to their scopes
7
7
  class IocRb::BeanFactory
8
+ attr_reader :const_loader
8
9
 
9
10
  # Constructor
10
11
  # @param beans_metadata_storage [BeansMetadataStorage] storage of bean metadatas
11
- def initialize(beans_metadata_storage)
12
+ def initialize(const_loader, beans_metadata_storage)
13
+ @const_loader = const_loader
12
14
  @beans_metadata_storage = beans_metadata_storage
13
15
  @singleton_scope = IocRb::Scopes::SingletonScope.new(self)
14
16
  @prototype_scope = IocRb::Scopes::PrototypeScope.new(self)
@@ -54,9 +56,7 @@ class IocRb::BeanFactory
54
56
  if bean_metadata.bean_class.is_a?(Class)
55
57
  bean_class = bean_metadata.bean_class
56
58
  else
57
- bean_class = bean_metadata.bean_class.split('::').inject(Object) do |mod, class_name|
58
- mod.const_get(class_name)
59
- end
59
+ bean_class = const_loader.load_const(bean_metadata.bean_class)
60
60
  bean_metadata.fetch_attrs!(bean_class)
61
61
  end
62
62
  bean = bean_metadata.instance ? bean_class.new : bean_class
@@ -79,7 +79,7 @@ class IocRb::BeanFactory
79
79
  bean_metadata.attrs.each do |attr|
80
80
  bean_metadata = @beans_metadata_storage.by_name(attr.ref)
81
81
  unless bean_metadata
82
- raise IocRb::Errors::MissingBeanError, "Bean with name :#{attr.ref} is not defined"
82
+ raise IocRb::Errors::MissingBeanError, "Bean with name :#{attr.ref} is not defined, check #{bean.class}"
83
83
  end
84
84
  case bean_metadata.scope
85
85
  when :singleton
@@ -0,0 +1,7 @@
1
+ module IocRb::ConstLoaders
2
+ module ActiveSupport
3
+ def self.load_const(const_name)
4
+ ActiveSupport::Inflector.constantize(const_name)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ module IocRb::ConstLoaders
2
+ module Native
3
+ def self.load_const(const_name)
4
+ const_name.split('::').inject(Object) do |mod, const_part|
5
+ mod.const_get(const_part)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -3,6 +3,7 @@ require 'ioc_rb/args_validator'
3
3
  require 'ioc_rb/bean_metadata'
4
4
  require 'ioc_rb/beans_metadata_storage'
5
5
  require 'ioc_rb/bean_factory'
6
+ require 'ioc_rb/const_loaders/native'
6
7
 
7
8
  module IocRb
8
9
 
@@ -11,20 +12,28 @@ module IocRb
11
12
  # providing a name and a class to create the object(we call them beans). Beans
12
13
  # may be retrieved by asking for them by name (via the [] operator)
13
14
  class Container
15
+ DEFAULT_CONST_LOADER = IocRb::ConstLoaders::Native
14
16
 
15
17
  # Constructor
16
18
  # @param resources [Array] array of procs with container's beans definitions
17
19
  # @param &block [Proc] optional proc with container's beans definitions
18
- def initialize(resources = nil, &block)
20
+ def initialize(const_loader = DEFAULT_CONST_LOADER, &block)
19
21
  @beans_metadata_storage = IocRb::BeansMetadataStorage.new
20
- @bean_factory = IocRb::BeanFactory.new(@beans_metadata_storage)
22
+ @bean_factory = IocRb::BeanFactory.new(const_loader, @beans_metadata_storage)
21
23
 
22
- if resources
23
- IocRb::ArgsValidator.is_array!(resources, :resources)
24
- load_bean_definitions(resources)
25
- end
26
- if block_given?
27
- load_bean_definitions([block])
24
+ block.call(self) if block_given?
25
+ end
26
+
27
+ # Evaluates the given array of blocks on the container instance
28
+ # what adds new bean definitions to the container
29
+ # @param resources [Array] array of procs with container's beans definitions
30
+ def self.new_with_beans(resources, const_loader = DEFAULT_CONST_LOADER)
31
+ IocRb::ArgsValidator.is_array!(resources, :resources)
32
+
33
+ self.new(const_loader).tap do |container|
34
+ resources.each do |resource|
35
+ resource.call(container)
36
+ end
28
37
  end
29
38
  end
30
39
 
@@ -50,16 +59,5 @@ module IocRb
50
59
  @bean_factory.get_bean(name)
51
60
  end
52
61
 
53
- private
54
-
55
- # Evaluates the given array of blocks on the container instance
56
- # what adds new bean definitions to the container
57
- # @param resources [Array] array of procs with container's beans definitions
58
- def load_bean_definitions(resources)
59
- resources.each do |resource|
60
- resource.call(self)
61
- end
62
- end
63
-
64
62
  end
65
63
  end
@@ -1,3 +1,3 @@
1
1
  module IocRb
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -44,7 +44,7 @@ describe IocRb::Container do
44
44
  end
45
45
 
46
46
  it "should instanciate given bean definitions" do
47
- container = IocRb::Container.new([resource])
47
+ container = IocRb::Container.new_with_beans([resource])
48
48
  container[:logger].should be_a(Logger)
49
49
  container[:appender].should be_a(Appender)
50
50
  end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require 'rubygems'
2
2
  require 'bundler/setup'
3
- require 'debugger'
4
3
 
5
4
  RSpec.configure do |config|
6
5
  config.color_enabled = true
metadata CHANGED
@@ -1,92 +1,81 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ioc_rb
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.1.1
4
+ version: 0.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Albert Gazizov
9
- - Ruslan Gatiyatov
10
8
  autorequire:
11
9
  bindir: bin
12
10
  cert_chain: []
13
- date: 2014-05-19 00:00:00.000000000 Z
11
+ date: 2015-02-13 00:00:00.000000000 Z
14
12
  dependencies:
15
13
  - !ruby/object:Gem::Dependency
16
- prerelease: false
17
14
  name: request_store
18
- type: :runtime
19
- version_requirements: !ruby/object:Gem::Requirement
15
+ requirement: !ruby/object:Gem::Requirement
20
16
  requirements:
21
- - - ! '>='
17
+ - - ">="
22
18
  - !ruby/object:Gem::Version
23
19
  version: '0'
24
- none: false
25
- requirement: !ruby/object:Gem::Requirement
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
- none: false
31
27
  - !ruby/object:Gem::Dependency
32
- prerelease: false
33
28
  name: activesupport
34
- type: :runtime
35
- version_requirements: !ruby/object:Gem::Requirement
29
+ requirement: !ruby/object:Gem::Requirement
36
30
  requirements:
37
- - - ! '>='
31
+ - - ">="
38
32
  - !ruby/object:Gem::Version
39
33
  version: '0'
40
- none: false
41
- requirement: !ruby/object:Gem::Requirement
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
- none: false
47
41
  - !ruby/object:Gem::Dependency
48
- prerelease: false
49
42
  name: bundler
50
- type: :development
51
- version_requirements: !ruby/object:Gem::Requirement
43
+ requirement: !ruby/object:Gem::Requirement
52
44
  requirements:
53
- - - ~>
45
+ - - "~>"
54
46
  - !ruby/object:Gem::Version
55
47
  version: '1.3'
56
- none: false
57
- requirement: !ruby/object:Gem::Requirement
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
58
51
  requirements:
59
- - - ~>
52
+ - - "~>"
60
53
  - !ruby/object:Gem::Version
61
54
  version: '1.3'
62
- none: false
63
55
  - !ruby/object:Gem::Dependency
64
- prerelease: false
65
56
  name: rake
66
- type: :development
67
- version_requirements: !ruby/object:Gem::Requirement
57
+ requirement: !ruby/object:Gem::Requirement
68
58
  requirements:
69
- - - ! '>='
59
+ - - ">="
70
60
  - !ruby/object:Gem::Version
71
61
  version: '0'
72
- none: false
73
- requirement: !ruby/object:Gem::Requirement
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
74
65
  requirements:
75
- - - ! '>='
66
+ - - ">="
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
- none: false
79
69
  description: Inversion of Controll Container
80
70
  email:
81
71
  - deeper4k@gmail.com
82
- - ruslan.gatiyatov@gmail.com
83
72
  executables: []
84
73
  extensions: []
85
74
  extra_rdoc_files: []
86
75
  files:
87
- - .gitignore
88
- - .travis.yml
89
- - .yardops
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - ".yardops"
90
79
  - Gemfile
91
80
  - Gemfile.lock
92
81
  - LICENSE.txt
@@ -98,6 +87,8 @@ files:
98
87
  - lib/ioc_rb/bean_factory.rb
99
88
  - lib/ioc_rb/bean_metadata.rb
100
89
  - lib/ioc_rb/beans_metadata_storage.rb
90
+ - lib/ioc_rb/const_loaders/active_support.rb
91
+ - lib/ioc_rb/const_loaders/native.rb
101
92
  - lib/ioc_rb/container.rb
102
93
  - lib/ioc_rb/errors.rb
103
94
  - lib/ioc_rb/inject.rb
@@ -112,33 +103,26 @@ files:
112
103
  homepage: http://github.com/deeper4k/ioc_rb
113
104
  licenses:
114
105
  - MIT
106
+ metadata: {}
115
107
  post_install_message:
116
108
  rdoc_options: []
117
109
  require_paths:
118
110
  - lib
119
111
  required_ruby_version: !ruby/object:Gem::Requirement
120
112
  requirements:
121
- - - ! '>='
113
+ - - ">="
122
114
  - !ruby/object:Gem::Version
123
- segments:
124
- - 0
125
- hash: 1078915959922104396
126
115
  version: '0'
127
- none: false
128
116
  required_rubygems_version: !ruby/object:Gem::Requirement
129
117
  requirements:
130
- - - ! '>='
118
+ - - ">="
131
119
  - !ruby/object:Gem::Version
132
- segments:
133
- - 0
134
- hash: 1078915959922104396
135
120
  version: '0'
136
- none: false
137
121
  requirements: []
138
122
  rubyforge_project:
139
- rubygems_version: 1.8.23
123
+ rubygems_version: 2.2.2
140
124
  signing_key:
141
- specification_version: 3
125
+ specification_version: 4
142
126
  summary: Inversion of Controll Container
143
127
  test_files:
144
128
  - spec/ioc_rb/container_spec.rb