dee-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a4816151bf891a4b63e3ce858158523af0681277
4
+ data.tar.gz: 97a07fec399a5a99209cf964294d004005f768f4
5
+ SHA512:
6
+ metadata.gz: b0549211e79fbb727295d0977d89913e97101e2245a5d15b9c1431a9d8f253509c78f8145221e47915876d506c40298ae521f1292f6561f32a8da3d1f731e8de
7
+ data.tar.gz: d14993816d9b969e2c7807055f77a54524b24edd3c78dee52564ed05952984a5068571d100d576fcf5776440156b49ad9146c27bfddd5b6399e791ecf18720c4
@@ -0,0 +1 @@
1
+ service_name: travis-ci
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ *.swp
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
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - 2.0.0
7
+
8
+ matrix:
9
+ allow_failures:
10
+ - rvm: 1.8.7
11
+ - rvm: 1.9.2
@@ -0,0 +1,7 @@
1
+ ChangeLog of dee-rails
2
+ ======================
3
+
4
+ 0.0.1 released 2014-01-01
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-rails.gemspec
4
+ gemspec
@@ -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
@@ -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.
@@ -0,0 +1,70 @@
1
+ # dee-rails
2
+
3
+ [![Build Status](https://travis-ci.org/yuya-takeyama/dee-rails.png?branch=develop)](https://travis-ci.org/yuya-takeyama/dee-rails)
4
+ [![Coverage Status](https://coveralls.io/repos/yuya-takeyama/dee-rails/badge.png?branch=develop)](https://coveralls.io/r/yuya-takeyama/dee-rails?branch=develop)
5
+
6
+ [Dee](https://github.com/yuya-takeyama/dee) the DI Container for Rails
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'dee-rails'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install dee-rails
21
+
22
+ ## Usage
23
+
24
+ ### Defining service provider
25
+
26
+ Write your service provider using generator.
27
+
28
+ $ rails g dee:service_provider foo
29
+ $ vi app/providers/foo_service_provider.rb
30
+
31
+ ```ruby
32
+ class FooServceProvider < Dee::Rails::ServiceProvider
33
+ provide do
34
+ # Configuration parameter
35
+ self['foo.name'] = 'FOO'
36
+
37
+ # Singleton service
38
+ singleton 'foo' do
39
+ Foo.new self['foo.name']
40
+ end
41
+
42
+ # Service
43
+ factory 'bar' do
44
+ Bar.new
45
+ end
46
+ end
47
+ end
48
+ ```
49
+
50
+ ### Using service
51
+
52
+ You can access services defined in provider using `Dee` object.
53
+
54
+ ```ruby
55
+ class FooController < ApplicationController
56
+ def show
57
+ foo = Dee['foo']
58
+
59
+ # Some instructions using Foo object
60
+ end
61
+ end
62
+ ```
63
+
64
+ ## Contributing
65
+
66
+ 1. Fork it
67
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
68
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
69
+ 4. Push to the branch (`git push origin my-new-feature`)
70
+ 5. Create new Pull Request
@@ -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
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dee/rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dee-rails"
8
+ spec.version = Dee::Rails::VERSION
9
+ spec.authors = ["Yuya Takeyama"]
10
+ spec.email = ["sign.of.the.wolf.pentagram@gmail.com"]
11
+ spec.description = %q{Dee the DI Container for Rails}
12
+ spec.summary = %q{Dee the DI Container for Rails}
13
+ spec.homepage = "https://github.com/yuya-takeyama/dee-rails"
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_dependency "dee", "~> 0.0.1"
22
+ spec.add_dependency "rails", ">= 3", "< 5"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "coveralls"
28
+ # Workaround for rest-client dependency
29
+ # https://github.com/rest-client/rest-client/issues/235
30
+ spec.add_development_dependency "mime-types", "< 2"
31
+ end
@@ -0,0 +1 @@
1
+ require 'dee/rails'
@@ -0,0 +1,31 @@
1
+ require "dee"
2
+ require "dee/rails/loader"
3
+ require "dee/rails/railtie" if defined? Rails
4
+ require "dee/rails/service_provider"
5
+ require "dee/rails/version"
6
+
7
+ module Dee
8
+ module Rails
9
+ def self.setup!
10
+ ::Dee.extend self
11
+ ::Dee.container = ::Dee::Container.new
12
+ ::Dee::Rails::Loader.load!
13
+ end
14
+
15
+ def container=(container)
16
+ @@container = container
17
+ end
18
+
19
+ def container
20
+ @@container
21
+ end
22
+
23
+ def [](key)
24
+ @@container[key]
25
+ end
26
+
27
+ def []=(key, value)
28
+ @@container[key] = value
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,25 @@
1
+ module Dee
2
+ module Rails
3
+ module Generators
4
+ class ServiceProviderGenerator < ::Rails::Generators::Base
5
+ source_root File.expand_path('../templates', __FILE__)
6
+ namespace 'dee:service_provider'
7
+
8
+ argument :name, :type => :string
9
+
10
+ def create_service_provider
11
+ template 'service_provider.rb', File.join('app', 'providers', service_provider_name + ".rb")
12
+ end
13
+
14
+ private
15
+ def class_name
16
+ ::ActiveSupport::Inflector.classify(service_provider_name)
17
+ end
18
+
19
+ def service_provider_name
20
+ name + "_service_provider"
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ class <%= class_name %> < Dee::Rails::ServiceProvider
2
+ provide do
3
+ # Your service provider definition goes here
4
+ end
5
+ end
@@ -0,0 +1,22 @@
1
+ module Dee
2
+ module Rails
3
+ class Loader
4
+ class << self
5
+ def load!
6
+ Dir.glob(providers_glob_path).each do |file|
7
+ load file
8
+ end
9
+ end
10
+
11
+ private
12
+ def providers_path
13
+ File.join(::Rails.root, 'app', 'providers')
14
+ end
15
+
16
+ def providers_glob_path
17
+ File.join(providers_path, '*_service_provider.rb')
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,13 @@
1
+ module Dee
2
+ module Rails
3
+ class Railtie < ::Rails::Railtie
4
+ config.to_prepare do
5
+ ::Dee::Rails.setup!
6
+ end
7
+
8
+ generators do
9
+ require 'dee/rails/generators/service_provider_generator'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ module Dee
2
+ module Rails
3
+ class ServiceProvider
4
+ class << self
5
+ def provide(&block)
6
+ Dee.container.instance_eval &block
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module Dee
2
+ module Rails
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,63 @@
1
+ describe Dee::Rails do
2
+ let(:rails_root) { File.expand_path('../../fixture/rails_app', __FILE__) }
3
+
4
+ before do
5
+ require File.join(rails_root, 'lib', 'foo')
6
+ end
7
+
8
+ context 'before Dee::Rails.setup! is called' do
9
+ describe 'Dee.container' do
10
+ it 'should be error' do
11
+ expect { Dee.container }.to raise_error
12
+ end
13
+ end
14
+ end
15
+
16
+ context 'after Dee::Rails.setup! is called' do
17
+ before do
18
+ ::Rails = double('Rails')
19
+ ::Rails.stub('root').and_return(rails_root)
20
+
21
+ Dee::Rails.setup!
22
+ end
23
+
24
+ after do
25
+ ::Rails = nil
26
+ end
27
+
28
+ describe 'Dee.container' do
29
+ it 'should be Dee::Container' do
30
+ expect(Dee.container).to be_a(Dee::Container)
31
+ end
32
+ end
33
+
34
+ describe 'Dee["foo.singleton"]' do
35
+ it 'should be a Foo object' do
36
+ expect(Dee['foo.singleton']).to be_a(Foo)
37
+ expect(Dee['foo.singleton'].name).to eq('FOO')
38
+ end
39
+
40
+ it 'should be always identical' do
41
+ expect(Dee['foo.singleton']).to be_equal(Dee['foo.singleton'])
42
+ end
43
+ end
44
+
45
+ describe 'Dee["foo.factory"]' do
46
+ it 'should be a Foo object' do
47
+ expect(Dee['foo.factory']).to be_a(Foo)
48
+ expect(Dee['foo.factory'].name).to eq('FOO')
49
+ end
50
+
51
+ it 'should not be identical' do
52
+ expect(Dee['foo.factory']).to_not be_equal(Dee['foo.factory'])
53
+ end
54
+ end
55
+
56
+ describe 'Dee["foo.name"]=' do
57
+ it "should override Foo's name" do
58
+ Dee['foo.name'] = 'overridden'
59
+ expect(Dee['foo.singleton'].name).to eq('overridden')
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,13 @@
1
+ class FooServceProvider < Dee::Rails::ServiceProvider
2
+ provide do
3
+ self['foo.name'] = 'FOO'
4
+
5
+ singleton 'foo.singleton' do
6
+ Foo.new self['foo.name']
7
+ end
8
+
9
+ factory 'foo.factory' do
10
+ Foo.new self['foo.name']
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ class Foo
2
+ attr_reader :name
3
+
4
+ def initialize(name)
5
+ @name = name
6
+ end
7
+ end
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'coveralls'
3
+ Coveralls.wear!
4
+ require 'dee-rails'
metadata ADDED
@@ -0,0 +1,175 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dee-rails
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-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dee
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '3'
34
+ - - <
35
+ - !ruby/object:Gem::Version
36
+ version: '5'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '3'
44
+ - - <
45
+ - !ruby/object:Gem::Version
46
+ version: '5'
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '1.3'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ version: '1.3'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rspec
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: coveralls
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: mime-types
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - <
108
+ - !ruby/object:Gem::Version
109
+ version: '2'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - <
115
+ - !ruby/object:Gem::Version
116
+ version: '2'
117
+ description: Dee the DI Container for Rails
118
+ email:
119
+ - sign.of.the.wolf.pentagram@gmail.com
120
+ executables: []
121
+ extensions: []
122
+ extra_rdoc_files: []
123
+ files:
124
+ - .coveralls.yml
125
+ - .gitignore
126
+ - .rspec
127
+ - .travis.yml
128
+ - ChangeLog.md
129
+ - Gemfile
130
+ - Guardfile
131
+ - LICENSE.txt
132
+ - README.md
133
+ - Rakefile
134
+ - dee-rails.gemspec
135
+ - lib/dee-rails.rb
136
+ - lib/dee/rails.rb
137
+ - lib/dee/rails/generators/service_provider_generator.rb
138
+ - lib/dee/rails/generators/templates/service_provider.rb
139
+ - lib/dee/rails/loader.rb
140
+ - lib/dee/rails/railtie.rb
141
+ - lib/dee/rails/service_provider.rb
142
+ - lib/dee/rails/version.rb
143
+ - spec/dee/rails_spec.rb
144
+ - spec/fixture/rails_app/app/providers/foo_service_provider.rb
145
+ - spec/fixture/rails_app/lib/foo.rb
146
+ - spec/spec_helper.rb
147
+ homepage: https://github.com/yuya-takeyama/dee-rails
148
+ licenses:
149
+ - MIT
150
+ metadata: {}
151
+ post_install_message:
152
+ rdoc_options: []
153
+ require_paths:
154
+ - lib
155
+ required_ruby_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ required_rubygems_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - '>='
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ requirements: []
166
+ rubyforge_project:
167
+ rubygems_version: 2.2.0
168
+ signing_key:
169
+ specification_version: 4
170
+ summary: Dee the DI Container for Rails
171
+ test_files:
172
+ - spec/dee/rails_spec.rb
173
+ - spec/fixture/rails_app/app/providers/foo_service_provider.rb
174
+ - spec/fixture/rails_app/lib/foo.rb
175
+ - spec/spec_helper.rb