roda-container 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5365074c2dcadd60d7bd776e6a7875b6139e5ea4
4
+ data.tar.gz: fc953960aaafd78ac65dae44fe7f46315bb8540d
5
+ SHA512:
6
+ metadata.gz: 3e5cf15a1e0c8f773f910041f0689f255c99ed142bfd926e29a8f5d71dc46dfea6424769d5b3e12e16182cb9b1cbf20bc62200dfba6fe8b5a1949f53dcadeff4
7
+ data.tar.gz: a0aeb38b04c25be7f612b7f76f774ccc421df0d43cc671118347dcc09f831b0e0827c41e779ed487c1272538df28891a04600e9d452a01e2126590a0fd5d1047
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Janko Marohnić
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # roda-container
2
+
3
+ A plugin for Roda which turns your application into a (IoC) container
4
+
5
+ ## Installation
6
+
7
+ ```ruby
8
+ gem 'roda-container', '0.0.1'
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ruby
14
+ class MyApplication < Roda
15
+ plugin :container
16
+ end
17
+
18
+ class UserRepository
19
+ def self.first
20
+ { name: 'Jack' }
21
+ end
22
+ end
23
+
24
+ MyApplication.register(:user_repository, UserRepository)
25
+ MyApplication.resolve(:user_repository).first
26
+ # => {:name=>"Jack"}
27
+
28
+ class PersonRepository
29
+ def first
30
+ { name: 'Gill' }
31
+ end
32
+ end
33
+
34
+ MyApplication.register(:person_repository, -> { PersonRepository.new })
35
+ MyApplication.resolve(:person_repository).first
36
+ # => {:name=>"Gill"}
37
+ ```
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork it ( https://github.com/AMHOL/roda-container )
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
43
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
44
+ 4. Push to the branch (`git push origin my-new-feature`)
45
+ 5. Create a new Pull Request
46
+
47
+ ## License
48
+
49
+ [MIT](LICENSE.txt)
@@ -0,0 +1,75 @@
1
+ class Roda
2
+ ContainerError = Class.new(::Exception)
3
+
4
+ module RodaPlugins
5
+ # The container plugin allows your application to
6
+ # act as a container, you can register values
7
+ # with your application (container) and resolve them later.
8
+ #
9
+ # If you register something that responds to call, the result of
10
+ # call will be returned each time you resolve it.
11
+ #
12
+ # Example:
13
+ #
14
+ # plugin :container
15
+ #
16
+ # class UserRepository
17
+ # def self.first
18
+ # { name: 'Jack' }
19
+ # end
20
+ # end
21
+ #
22
+ # MyApplication.register(:user_repository, UserRepository)
23
+ # MyApplication.resolve(:user_repository).first
24
+ #
25
+ # class PersonRepository
26
+ # def first
27
+ # { name: 'Gill' }
28
+ # end
29
+ # end
30
+ #
31
+ # MyApplication.register(:person_repository, -> { PersonRepository.new })
32
+ # MyApplication.resolve(:person_repository).first
33
+ module Container
34
+ module ClassMethods
35
+ # Whether middleware from the current class should be inherited by subclasses.
36
+ # True by default, should be set to false when using a design where the parent
37
+ # class accepts requests and uses run to dispatch the request to a subclass.
38
+ attr_reader :container
39
+ private :container
40
+
41
+ def self.extended(subclass)
42
+ subclass.instance_variable_set(:@container, RodaCache.new)
43
+ super
44
+ end
45
+
46
+ def inherited(subclass)
47
+ subclass.instance_variable_set(:@container, container)
48
+ super
49
+ end
50
+
51
+ def register(key, contents = nil, &block)
52
+ container[key] = block_given? ? block : contents
53
+ end
54
+
55
+ def resolve(key)
56
+ instance = container.fetch(key) do
57
+ fail ::Roda::ContainerError, "Nothing registered with the name #{key}"
58
+ end
59
+ instance.respond_to?(:call) ? instance.call : instance
60
+ end
61
+
62
+ def detach_container
63
+ @container = container.dup
64
+ end
65
+
66
+ def freeze
67
+ container.freeze
68
+ super
69
+ end
70
+ end
71
+ end
72
+
73
+ register_plugin(:container, Container)
74
+ end
75
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: roda-container
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Andy Holland
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-30 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: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: roda
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '10.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '10.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '3.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '3.2'
69
+ description: A plugin for Roda which turns your application into a (IoC) container
70
+ email:
71
+ - andyholland1991@aol.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - LICENSE.txt
77
+ - README.md
78
+ - lib/roda/plugins/container.rb
79
+ homepage: https://github.com/AMHOL/roda-container
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.4.6
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: A plugin for Roda which turns your application into a (IoC) container
103
+ test_files: []