morphine 0.1.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.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "http://rubygems.org"
2
+ gemspec
3
+
4
+ group :development do
5
+ gem 'rake'
6
+ gem 'guard'
7
+ gem 'guard-rspec'
8
+ gem 'guard-bundler'
9
+ gem 'growl'
10
+ end
data/Guardfile ADDED
@@ -0,0 +1,10 @@
1
+ guard 'bundler' do
2
+ watch('Gemfile')
3
+ watch(/^.+\.gemspec/)
4
+ end
5
+
6
+ guard 'rspec', :version => 2 do
7
+ watch(%r{^spec/.+_spec\.rb$})
8
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
9
+ watch('spec/spec_helper.rb') { "spec" }
10
+ end
data/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # Morphine
2
+
3
+ **NOTE: I am in the process of extracting dependency injection features from [Gaug.es](http://get.gaug.es). Currently, the only feature of this library is memoization. I am not dumb or inexperienced. I'm just not done yet.**
4
+
5
+ Morphine is a lightweight dependency injection framework for Ruby. It uses a simple Ruby DSL to ease the pain of wiring your dependencies together.
6
+
7
+ ## Usage
8
+
9
+ Create a container for your dependencies and include the `Morphine` module.
10
+
11
+ ```ruby
12
+ class Application
13
+ include Morphine
14
+
15
+ register :track_service do
16
+ KestrelTrackService.new(kestrel_client, config.tracking_queue)
17
+ end
18
+
19
+ register :track_processor do
20
+ KestrelTrackProcessor.new(blocking_kestrel_client, config.tracking_queue)
21
+ end
22
+
23
+ private
24
+
25
+ register :kestrel_client do
26
+ c = config['kestrel'].dup
27
+ Kestrel::Client.new(c.delete('servers'), c.symbolize_keys)
28
+ end
29
+
30
+ register :blocking_kestrel_client do
31
+ Kestrel::Client::Blocking.new(kestrel_client)
32
+ end
33
+ end
34
+ ```
35
+
36
+ Create an instance of your container, and use that to load your dependencies
37
+
38
+ ```ruby
39
+ $app = Application.new
40
+
41
+ get '/track.gif' do
42
+ $app.track_processor.record(params['h'])
43
+ end
44
+ ```
45
+
46
+ # But I don't need dependency injection in Ruby!
47
+
48
+ Many [argue](http://weblog.jamisbuck.org/2008/11/9/legos-play-doh-and-programming) that you [don't](http://davybrion.com/blog/2010/10/why-you-dont-need-dependency-injection-in-ruby/) [need](http://fabiokung.com/2010/05/06/ruby-and-dependency-injection-in-a-dynamic-world/) dependency injection in dynamic languages like Ruby. What they are really saying is you don't need a complicated dependency injection framework, and *they're right*.
49
+
50
+ That's why Morphine is an extremely simple library.
51
+
52
+ ## Contributing
53
+
54
+ If you find what looks like a bug:
55
+
56
+ 1. Check the [GitHub issue tracker](http://github.com/bkeepers/morphine/issues/) to see if anyone else has reported issue.
57
+ 2. If you don't see anything, create an issue with information on how to reproduce it.
58
+
59
+ If you want to contribute an enhancement or a fix:
60
+
61
+ 1. Fork the project on GitHub.
62
+ 2. Make your changes with tests.
63
+ 3. Commit the changes without making changes to the Rakefile, Gemfile, gemspec, or any other files that aren't related to your enhancement or fix
64
+ 4. Send a pull request.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
data/lib/morphine.rb ADDED
@@ -0,0 +1,23 @@
1
+ require "morphine/version"
2
+
3
+ module Morphine
4
+ def self.included(base)
5
+ base.extend ClassMethods
6
+ end
7
+
8
+ def dependencies
9
+ @dependencies ||= {}
10
+ end
11
+
12
+ module ClassMethods
13
+ def register(name, &block)
14
+ define_method name do
15
+ dependencies[name] ||= instance_eval(&block)
16
+ end
17
+
18
+ define_method "#{name}=" do |service|
19
+ dependencies[name] = service
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module Morphine
2
+ VERSION = "0.1.0"
3
+ end
data/morphine.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'morphine/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'morphine'
7
+ s.version = Morphine::VERSION
8
+ s.authors = ['Brandon Keepers']
9
+ s.email = ['brandon@opensoul.org']
10
+ s.homepage = ''
11
+ s.summary = %q{A lightweight dependency injection framework for Ruby}
12
+ s.description = %q{Morphine is a lightweight dependency injection framework for Ruby. It uses a simple Ruby DSL to ease the pain of wiring your dependencies together.}
13
+
14
+ s.rubyforge_project = 'morphine'
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ['lib']
20
+
21
+ s.add_development_dependency 'rspec', '~>2.0'
22
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Morphine do
4
+ let :Container do
5
+ Class.new do
6
+ include Morphine
7
+ end
8
+ end
9
+
10
+ let(:container) { Container().new }
11
+
12
+ describe 'register' do
13
+ before do
14
+ Container().register(:client) { 'client' }
15
+ end
16
+
17
+ it 'yields block to instantiate dependency' do
18
+ container.client.should == 'client'
19
+ end
20
+
21
+ it 'memoizes result' do
22
+ container.client.object_id.should == container.client.object_id
23
+ end
24
+
25
+ it 'instance evals block to resolve dependencies' do
26
+ Container().register(:service) { Struct.new(:client).new(client) }
27
+ container.service.client.should == container.client
28
+ end
29
+
30
+ it 'defines writer method to change service' do
31
+ container.client = 'new client'
32
+ container.client.should eq('new client')
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,6 @@
1
+ require 'bundler'
2
+ Bundler.require :default, :test
3
+ require 'morphine'
4
+
5
+ RSpec.configure do |config|
6
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: morphine
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Brandon Keepers
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-04-09 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 2
31
+ - 0
32
+ version: "2.0"
33
+ type: :development
34
+ version_requirements: *id001
35
+ description: Morphine is a lightweight dependency injection framework for Ruby. It uses a simple Ruby DSL to ease the pain of wiring your dependencies together.
36
+ email:
37
+ - brandon@opensoul.org
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files: []
43
+
44
+ files:
45
+ - .gitignore
46
+ - Gemfile
47
+ - Guardfile
48
+ - README.md
49
+ - Rakefile
50
+ - lib/morphine.rb
51
+ - lib/morphine/version.rb
52
+ - morphine.gemspec
53
+ - spec/morphine_spec.rb
54
+ - spec/spec_helper.rb
55
+ homepage: ""
56
+ licenses: []
57
+
58
+ post_install_message:
59
+ rdoc_options: []
60
+
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ hash: 3
69
+ segments:
70
+ - 0
71
+ version: "0"
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ hash: 3
78
+ segments:
79
+ - 0
80
+ version: "0"
81
+ requirements: []
82
+
83
+ rubyforge_project: morphine
84
+ rubygems_version: 1.8.10
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: A lightweight dependency injection framework for Ruby
88
+ test_files:
89
+ - spec/morphine_spec.rb
90
+ - spec/spec_helper.rb