dee 0.0.1

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: 9d68d4d9e4c3ab4b19f235b85cfdd23d940bfbd8
4
+ data.tar.gz: 86fd1cdf1c5aa29d6bb0d0d5915e41ca599015ee
5
+ SHA512:
6
+ metadata.gz: 78b788b43f08281345baf27b58a765ee4963b68c3706e3e7da7ca5e90695d890f7affe5c8db01bbf927c990500f5042f277377aaaa19b88d7669219de28eccb1
7
+ data.tar.gz: 2d70a6a7eed1ef5f07043824392478e06cad970ec632a58c852e7dcf773ae0fdadc030ab83bd36847885b9c7c415ba769f8d0633d20d41c6411223638a10bcf4
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.swp
2
+ *.gem
3
+ *.rbc
4
+ /.bundle
5
+ /.config
6
+ .yardoc
7
+ /Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ /vendor
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.1
5
+ - 1.9.2
6
+ - 1.9.3
7
+ - 2.0.0
data/ChangeLog.md ADDED
@@ -0,0 +1,7 @@
1
+ ChangeLog of Dee
2
+ ================
3
+
4
+ 0.0.1 released 2013-12-08
5
+ -------------------------
6
+
7
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dee.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,5 @@
1
+ guard :rspec do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Yuya Takeyama
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Dee
2
+
3
+ Simple DI Container/Service Locater for Ruby
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'dee'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install dee
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/dee.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dee/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dee"
8
+ spec.version = Dee::VERSION
9
+ spec.authors = ["Yuya Takeyama"]
10
+ spec.email = ["sign.of.the.wolf.pentagram@gmail.com"]
11
+ spec.description = %q{Simple DI Container/Service Locater for Ruby}
12
+ spec.summary = %q{Simple DI Container/Service Locater for Ruby}
13
+ spec.homepage = "https://github.com/yuya-takeyama/dee"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake", "~> 10.1.0"
23
+ spec.add_development_dependency "rspec", "~> 2.14.1"
24
+ spec.add_development_dependency "guard-rspec", "~> 4.2.0"
25
+ end
data/lib/dee.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "dee/container"
2
+ require "dee/version"
3
+
4
+ module Dee
5
+ end
@@ -0,0 +1,53 @@
1
+ module Dee
2
+ class Container
3
+ class Factory
4
+ def initialize(&block)
5
+ @block = block
6
+ end
7
+
8
+ def create
9
+ @block.call
10
+ end
11
+ end
12
+
13
+ class SingletonFactory < Factory
14
+ def initialize(&block)
15
+ @block = block
16
+ @value = nil
17
+ end
18
+
19
+ def create
20
+ @value = @block.call unless @value
21
+ @value
22
+ end
23
+ end
24
+
25
+ def initialize
26
+ @values = Hash.new
27
+ end
28
+
29
+ def factory(key, &block)
30
+ @values[key] = Factory.new(&block)
31
+ end
32
+
33
+ def singleton(key, &block)
34
+ @values[key] = SingletonFactory.new(&block)
35
+ end
36
+
37
+ def [](key)
38
+ raise "'%s' is not defined in container" unless @values.key? key
39
+
40
+ value = @values[key]
41
+
42
+ if value.kind_of? Factory
43
+ value.create
44
+ else
45
+ value
46
+ end
47
+ end
48
+
49
+ def []=(key, value)
50
+ @values[key] = value
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,3 @@
1
+ module Dee
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,53 @@
1
+ describe Dee::Container do
2
+ let(:container) { Dee::Container.new }
3
+
4
+ describe '#[]' do
5
+ it 'raises error when no defined key is specified' do
6
+ expect { container['no_defined_key'] }.to raise_error
7
+ end
8
+ end
9
+
10
+ describe '#[]=' do
11
+ it 'sets value in container' do
12
+ container['key'] = 'value'
13
+ expect(container['key']).to eq('value')
14
+ end
15
+ end
16
+
17
+ describe '#singleton' do
18
+ before do
19
+ container.singleton 'hash' do
20
+ Hash.new
21
+ end
22
+ end
23
+
24
+ it 'creates object defined in factory' do
25
+ expect(container['hash']).to eq(Hash.new)
26
+ end
27
+
28
+ it 'always returns same object' do
29
+ a = container['hash']
30
+ expect(container['hash']).to equal(a)
31
+ end
32
+ end
33
+
34
+ describe '#factory' do
35
+ before do
36
+ container.factory 'hash' do
37
+ Hash.new
38
+ end
39
+ end
40
+
41
+ it 'creates object defined in factory' do
42
+ expect(container['hash']).to eq(Hash.new)
43
+ end
44
+
45
+ it 'always create new object' do
46
+ a = container['hash']
47
+ b = container['hash']
48
+
49
+ expect(b).to eq(Hash.new)
50
+ expect(b).to_not equal(a)
51
+ end
52
+ end
53
+ end
data/spec/dee_spec.rb ADDED
@@ -0,0 +1,5 @@
1
+ describe Dee do
2
+ it 'should have a version number' do
3
+ Dee::VERSION.should_not be_nil
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'dee'
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dee
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yuya Takeyama
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 10.1.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 10.1.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 2.14.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 2.14.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 4.2.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 4.2.0
69
+ description: Simple DI Container/Service Locater for Ruby
70
+ email:
71
+ - sign.of.the.wolf.pentagram@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .rspec
78
+ - .travis.yml
79
+ - ChangeLog.md
80
+ - Gemfile
81
+ - Guardfile
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - dee.gemspec
86
+ - lib/dee.rb
87
+ - lib/dee/container.rb
88
+ - lib/dee/version.rb
89
+ - spec/dee/container_spec.rb
90
+ - spec/dee_spec.rb
91
+ - spec/spec_helper.rb
92
+ homepage: https://github.com/yuya-takeyama/dee
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.1.11
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Simple DI Container/Service Locater for Ruby
116
+ test_files:
117
+ - spec/dee/container_spec.rb
118
+ - spec/dee_spec.rb
119
+ - spec/spec_helper.rb