dependancy 0.0.1

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,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ pkg/*
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ script: 'bundle exec rspec'
3
+ rvm:
4
+ - 1.9.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source :rubygems
2
+
3
+ # Specify your gem's dependencies in dependancy.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,8 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :version => 2 do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { 'spec' }
8
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Aaron Tian
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/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012, Aaron Tian
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # Dependancy
2
+
3
+ Getters & setters for dependency injection
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'dependancy'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install dependancy
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ class Bar
23
+ attr_accessor :name
24
+ end
25
+
26
+ class Foo
27
+ include Dependancy
28
+
29
+ def name
30
+ 'foo name'
31
+ end
32
+
33
+ dependancy :bar1 do
34
+ Bar.new
35
+ end
36
+
37
+ dependancy :bar2 do |foo|
38
+ bar = Bar.new
39
+ bar.name = foo.name
40
+ bar
41
+ end
42
+
43
+ dependancy :bar3
44
+ end
45
+
46
+ Foo._dependancies == [:bar1, :bar2, :bar3] # true
47
+ foo = Foo.new
48
+ foo.bar1.is_a? Bar # true
49
+ foo.bar2.is_a? Bar # true
50
+ foo.bar2.name == foo.name # true
51
+
52
+ ```
53
+
54
+ Tested in ruby 1.9.2
55
+ [![Build Status](https://secure.travis-ci.org/Aaron2Ti/dependancy.png)](http://travis-ci.org/Aaron2Ti/dependancy)
56
+
57
+ ## Contributing
58
+
59
+ 1. Fork it
60
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
61
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
62
+ 4. Push to the branch (`git push origin my-new-feature`)
63
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/dependancy/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ['Aaron Tian']
6
+ gem.email = ['Aaron2Ti@gmail.com']
7
+ gem.description = %q{Getters & setters for dependency injection}
8
+ gem.summary = %q{Java style getters & setters with default values}
9
+ gem.homepage = 'https://github.com/Aaron2Ti/dependancy'
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = 'dependancy'
15
+ gem.require_paths = ['lib']
16
+ gem.version = Dependancy::VERSION
17
+
18
+ gem.add_development_dependency 'rspec'
19
+ gem.add_development_dependency 'guard-rspec'
20
+ gem.add_development_dependency 'ruby-debug19'
21
+ end
data/lib/dependancy.rb ADDED
@@ -0,0 +1,29 @@
1
+ require "dependancy/version"
2
+
3
+ module Dependancy
4
+ def self.included(base)
5
+ base.extend ClassMethods
6
+ end
7
+
8
+ module ClassMethods
9
+ def _dependancies
10
+ @_dependancies || []
11
+ end
12
+
13
+ def dependancy(name, &block)
14
+ @_dependancies ||= []
15
+ @_dependancies << name
16
+
17
+ unless block_given?
18
+ attr_accessor name
19
+
20
+ else
21
+ attr_writer name
22
+
23
+ define_method name do
24
+ yield self
25
+ end
26
+ end
27
+ end
28
+ end # module ClassMethods
29
+ end
@@ -0,0 +1,3 @@
1
+ module Dependancy
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+ require 'dependancy'
3
+
4
+ describe Dependancy do
5
+ class Bar
6
+ attr_accessor :name
7
+ end
8
+
9
+ class Foo
10
+ include Dependancy
11
+
12
+ def name
13
+ 'foo name'
14
+ end
15
+
16
+ dependancy :bar1 do
17
+ Bar.new
18
+ end
19
+
20
+ dependancy :bar2 do |foo|
21
+ bar = Bar.new
22
+ bar.name = foo.name
23
+ bar
24
+ end
25
+
26
+ dependancy :bar3
27
+ end
28
+
29
+ it '._dependancies' do
30
+ Foo._dependancies.should have(3).items
31
+ Foo._dependancies.should == [:bar1, :bar2, :bar3]
32
+ end
33
+
34
+ it 'dependancy have default value' do
35
+ foo = Foo.new
36
+ foo.bar1.should be_a Bar
37
+ end
38
+
39
+ it 'dependancy could access current object' do
40
+ foo = Foo.new
41
+ bar = foo.bar2
42
+ bar.name.should == 'foo name'
43
+ end
44
+
45
+ it 'assign a new dependancy' do
46
+ foo = Foo.new
47
+ old_bar = foo.bar1
48
+ foo.bar1 = Bar.new
49
+
50
+ foo.bar1.should_not == old_bar
51
+ end
52
+ end
@@ -0,0 +1,13 @@
1
+ RSpec.configure do |config|
2
+ # ## Mock Framework
3
+ #
4
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
5
+ #
6
+ # config.mock_with :mocha
7
+ # config.mock_with :flexmock
8
+ # config.mock_with :rr
9
+
10
+ config.filter_run focus: true
11
+ config.run_all_when_everything_filtered = true
12
+ config.treat_symbols_as_metadata_keys_with_true_values = true
13
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dependancy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Aaron Tian
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-15 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &9227050 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *9227050
25
+ - !ruby/object:Gem::Dependency
26
+ name: guard-rspec
27
+ requirement: &9226840 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *9226840
36
+ - !ruby/object:Gem::Dependency
37
+ name: ruby-debug19
38
+ requirement: &9226630 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *9226630
47
+ description: Getters & setters for dependency injection
48
+ email:
49
+ - Aaron2Ti@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - .travis.yml
56
+ - Gemfile
57
+ - Guardfile
58
+ - LICENSE
59
+ - MIT-LICENSE
60
+ - README.md
61
+ - Rakefile
62
+ - dependancy.gemspec
63
+ - lib/dependancy.rb
64
+ - lib/dependancy/version.rb
65
+ - spec/lib/dependancy_spec.rb
66
+ - spec/spec_helper.rb
67
+ homepage: https://github.com/Aaron2Ti/dependancy
68
+ licenses: []
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 1.8.15
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: Java style getters & setters with default values
91
+ test_files:
92
+ - spec/lib/dependancy_spec.rb
93
+ - spec/spec_helper.rb
94
+ has_rdoc: