chickadee 6.0.5 → 7.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 883fe7efbded160bb722acc23475ad409e469d96
4
- data.tar.gz: d274eb18c304b9a097a13a7f42905a13ad4b4842
3
+ metadata.gz: dbf8380c0a57e470589b4365513b5f10d9ff2ef2
4
+ data.tar.gz: 319303850926d99613c3b206c8da857ccc53d6ec
5
5
  SHA512:
6
- metadata.gz: bb75f18ee45cf9ffab735300d67fe2b76490a65cfbd85277d03b4587b429f3e065d93bbfc746509e8e26fdc5600581f53fff6d6e648332c394bcd61066bc0f43
7
- data.tar.gz: 6db2a0e20e5b34ac3246fe669c9ce145342714f1d7094dc994067616e509db9c6f35b72c18575967709c73e39cc7ea92c59dd75f54828f1234de6e2c0101ec11
6
+ metadata.gz: 65578fc60ea269ffe5ffe512468faf1ca49783558854a5d5c68ecb4e8478f23b0ce6f416747f8aa39ff87c8bc840c07ef68a9935dff4960121d78d803636168f
7
+ data.tar.gz: 2fb848d80c3579526303d131f1deeb46cec76785e2a41e7ec70f12b0c9225312719506517a950a922674020dce52962814f6e59379f2a0c0cb37d3210e2c753e
data/chickadee.gemspec CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Chickadee::VERSION
9
9
  spec.authors = ["Erik Lott"]
10
10
  spec.email = ["erik.lott@evrium.com"]
11
- spec.description = %q{Lightweight command library}
12
- spec.summary = %q{Lightweight command library}
11
+ spec.description = %q{Minimal domain driven design library}
12
+ spec.summary = %q{Minimal domain driven design library}
13
13
  spec.homepage = ""
14
14
  spec.license = "MIT"
15
15
 
@@ -18,7 +18,9 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "ioc", "~> 2.2.0"
21
+ spec.add_dependency "ioc", "~> 4.1.0"
22
+ spec.add_dependency "rack", "~> 1.5.2"
23
+ spec.add_dependency "lotus-router", "~> 0.1.1"
22
24
 
23
25
  spec.add_development_dependency "bundler", "~> 1.3"
24
26
  spec.add_development_dependency "rake"
@@ -0,0 +1,47 @@
1
+ require "chickadee/container"
2
+ require "rack/request"
3
+ require "rack/response"
4
+ require "rack/builder"
5
+
6
+ module Chickadee
7
+ class Application
8
+ def initialize(
9
+ installers: [],
10
+ request: Rack::Request,
11
+ response: Rack::Response,
12
+ container: Container,
13
+ builder: Rack::Builder,
14
+ use: []
15
+ )
16
+ @installers = installers
17
+ @request_class = request
18
+ @response_class = response
19
+ @container_class = container
20
+ @builder_class = builder
21
+ @use_cache = use
22
+ end
23
+
24
+ def use(*args, &block)
25
+ @use_cache << [args, block]
26
+ end
27
+
28
+ def service(name)
29
+ builder = @builder_class.new
30
+ @use_cache.each { |use| builder.use(*use[0], &use[1]) }
31
+ builder.run(service_app(name))
32
+ builder
33
+ end
34
+
35
+ private
36
+
37
+ def service_app(name)
38
+ Proc.new do |env|
39
+ request = @request_class.new(env)
40
+ response = @response_class.new
41
+ container = @container_class.new
42
+ @installers.each{ |installer| installer.call(container) }
43
+ container.resolve(name).call(request, response)
44
+ end
45
+ end
46
+ end
47
+ end
@@ -1,35 +1,5 @@
1
- require 'ioc'
1
+ require "ioc"
2
2
 
3
3
  module Chickadee
4
- class Container < ::IOC::Container
5
- def register_handler(*args)
6
- auto_register(*args)
7
- end
8
-
9
- def auto_register(klass)
10
- register(
11
- underscore(demodulize(klass.name)).to_sym,
12
- klass
13
- )
14
- end
15
-
16
- def resolve_handler_for(request)
17
- resolve(underscore(demodulize("#{request.class.name}Handler")).to_sym)
18
- end
19
-
20
- private
21
-
22
- def underscore(str)
23
- str
24
- .gsub(/::/, '/')
25
- .gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
26
- .gsub(/([a-z\d])([A-Z])/,'\1_\2')
27
- .tr("-", "_")
28
- .downcase
29
- end
30
-
31
- def demodulize(constant_name)
32
- constant_name.split('::').last
33
- end
34
- end
4
+ class Container < ::IOC::Container; end
35
5
  end
@@ -0,0 +1,5 @@
1
+ require "lotus/router"
2
+
3
+ module Chickadee
4
+ class Router < ::Lotus::Router; end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module Chickadee
2
- VERSION = "6.0.5"
2
+ VERSION = "7.0.0"
3
3
  end
@@ -0,0 +1,24 @@
1
+ module Chickadee
2
+ class NumericID
3
+ def initialize(id)
4
+ raise(ArgumentError, "invalid id: #{id}") unless id.is_a?(Integer) && id > 0
5
+ @id = id
6
+ end
7
+
8
+ def to_i
9
+ @id
10
+ end
11
+
12
+ def ==(other)
13
+ self.class == other.class && self.hash == other.hash
14
+ end
15
+
16
+ def eql?(other)
17
+ self == other
18
+ end
19
+
20
+ def hash
21
+ @id.hash
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,26 @@
1
+ module Chickadee
2
+ class UUID
3
+ UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
4
+
5
+ def initialize(uuid)
6
+ raise(ArgumentError, "invalid uuid: #{uuid}") unless uuid.is_a?(String) && uuid.match(UUID_REGEX)
7
+ @uuid = uuid
8
+ end
9
+
10
+ def to_s
11
+ @uuid
12
+ end
13
+
14
+ def ==(other)
15
+ self.class == other.class && self.hash == other.hash
16
+ end
17
+
18
+ def eql?(other)
19
+ self == other
20
+ end
21
+
22
+ def hash
23
+ @uuid.hash
24
+ end
25
+ end
26
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,2 @@
1
1
  require 'minitest/autorun'
2
- require 'mocha/setup'
3
-
4
- def context *args, &block
5
- describe *args, &block
6
- end
2
+ require 'mocha/setup'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chickadee
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.5
4
+ version: 7.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik Lott
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-06 00:00:00.000000000 Z
11
+ date: 2014-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ioc
@@ -16,14 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.2.0
19
+ version: 4.1.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.2.0
26
+ version: 4.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.5.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.5.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: lotus-router
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.1.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.1
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: bundler
29
57
  requirement: !ruby/object:Gem::Requirement
@@ -66,7 +94,7 @@ dependencies:
66
94
  - - "~>"
67
95
  - !ruby/object:Gem::Version
68
96
  version: 1.0.0
69
- description: Lightweight command library
97
+ description: Minimal domain driven design library
70
98
  email:
71
99
  - erik.lott@evrium.com
72
100
  executables: []
@@ -81,9 +109,12 @@ files:
81
109
  - Rakefile
82
110
  - chickadee.gemspec
83
111
  - lib/chickadee.rb
112
+ - lib/chickadee/application.rb
84
113
  - lib/chickadee/container.rb
114
+ - lib/chickadee/router.rb
85
115
  - lib/chickadee/version.rb
86
- - spec/container_spec.rb
116
+ - lib/chickadee/vos/numeric_id.rb
117
+ - lib/chickadee/vos/uuid.rb
87
118
  - spec/spec_helper.rb
88
119
  homepage: ''
89
120
  licenses:
@@ -108,7 +139,6 @@ rubyforge_project:
108
139
  rubygems_version: 2.2.2
109
140
  signing_key:
110
141
  specification_version: 4
111
- summary: Lightweight command library
142
+ summary: Minimal domain driven design library
112
143
  test_files:
113
- - spec/container_spec.rb
114
144
  - spec/spec_helper.rb
@@ -1,33 +0,0 @@
1
- require 'spec_helper'
2
- require 'chickadee/container'
3
-
4
- describe Chickadee::Container do
5
- describe '#auto_register' do
6
- it 'registers class using class name' do
7
- class TestClass; end
8
- container = Chickadee::Container.new
9
- container.auto_register(TestClass)
10
- container.resolve(:test_class).wont_be_nil
11
- end
12
- end
13
-
14
- describe '#register_handler' do
15
- it 'registers handler using class name' do
16
- class TestRequestHandler; end
17
- container = Chickadee::Container.new
18
- container.auto_register(TestRequestHandler)
19
- container.resolve(:test_request_handler).wont_be_nil
20
- end
21
- end
22
-
23
- describe '#resolve_handler_for' do
24
- it 'registers handler using class name' do
25
- class TestRequest; end
26
- class TestRequestHandler; end
27
- container = Chickadee::Container.new
28
- request = TestRequest.new
29
- container.register(:test_request_handler, TestRequestHandler)
30
- container.resolve_handler_for(request).must_be_instance_of(TestRequestHandler)
31
- end
32
- end
33
- end