scorpion-ioc 0.0.1 → 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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +14 -10
  3. data/README.md +414 -26
  4. data/circle.yml +5 -0
  5. data/config.ru +7 -0
  6. data/lib/scorpion.rb +87 -0
  7. data/lib/scorpion/attribute.rb +71 -0
  8. data/lib/scorpion/attribute_set.rb +96 -0
  9. data/lib/scorpion/error.rb +29 -0
  10. data/lib/scorpion/hunter.rb +54 -0
  11. data/lib/scorpion/hunting_map.rb +115 -0
  12. data/lib/scorpion/king.rb +150 -0
  13. data/lib/scorpion/locale/en.yml +5 -0
  14. data/lib/scorpion/nest.rb +37 -0
  15. data/lib/scorpion/prey.rb +94 -0
  16. data/lib/scorpion/prey/builder_prey.rb +32 -0
  17. data/lib/scorpion/prey/captured_prey.rb +44 -0
  18. data/lib/scorpion/prey/class_prey.rb +13 -0
  19. data/lib/scorpion/prey/hunted_prey.rb +14 -0
  20. data/lib/scorpion/prey/module_prey.rb +14 -0
  21. data/lib/scorpion/rails.rb +1 -1
  22. data/lib/scorpion/rails/controller.rb +89 -0
  23. data/lib/scorpion/version.rb +1 -1
  24. data/scorpion.gemspec +2 -0
  25. data/spec/internal/config/database.yml +3 -0
  26. data/spec/internal/config/routes.rb +3 -0
  27. data/spec/internal/db/combustion_test.sqlite +0 -0
  28. data/spec/internal/db/schema.rb +3 -0
  29. data/spec/internal/log/.gitignore +1 -0
  30. data/spec/internal/public/favicon.ico +0 -0
  31. data/spec/lib/scorpion/attribute_set_spec.rb +89 -0
  32. data/spec/lib/scorpion/attribute_spec.rb +8 -0
  33. data/spec/lib/scorpion/error_spec.rb +8 -0
  34. data/spec/lib/scorpion/hunter_spec.rb +69 -0
  35. data/spec/lib/scorpion/hunting_map_spec.rb +118 -0
  36. data/spec/lib/scorpion/{scorpion.rb → instance_spec.rb} +0 -0
  37. data/spec/lib/scorpion/king_spec.rb +129 -0
  38. data/spec/lib/scorpion/prey/module_prey_spec.rb +16 -0
  39. data/spec/lib/scorpion/prey_spec.rb +76 -0
  40. data/spec/lib/scorpion/rails/controller_spec.rb +111 -0
  41. data/spec/lib/scorpion_spec.rb +0 -1
  42. data/spec/spec_helper.rb +6 -0
  43. metadata +78 -6
  44. data/Procfile +0 -1
  45. data/lib/scorpion/rails/railtie.rb +0 -15
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ module Test
4
+ module ModulePrey
5
+ module Example; end
6
+ end
7
+ end
8
+ describe Scorpion::Prey::ModulePrey do
9
+ let( :scorpion ){ double }
10
+ let( :prey ) { Scorpion::Prey::ModulePrey.new( Test::ModulePrey::Example ) }
11
+
12
+ it "returns the module itself" do
13
+ expect( prey.fetch( scorpion ) ).to be Test::ModulePrey::Example
14
+ end
15
+
16
+ end
@@ -0,0 +1,76 @@
1
+ require 'spec_helper'
2
+
3
+ module Test
4
+ module Prey
5
+ module Mod; end
6
+ class Base; end
7
+ class Derived < Base
8
+ include Mod
9
+ end
10
+ end
11
+ end
12
+
13
+ describe Scorpion::Prey do
14
+ context "inheritance" do
15
+ let( :prey ){ Scorpion::Prey.new( Test::Prey::Derived ) }
16
+
17
+ it "matches more derived class when looking for base class" do
18
+ expect( prey.satisfies? Test::Prey::Base ).to be_truthy
19
+ end
20
+
21
+ it "matches same class when looking for base class" do
22
+ expect( prey.satisfies? Test::Prey::Derived ).to be_truthy
23
+ end
24
+
25
+ it "does not inherit symbols" do
26
+ expect( Scorpion::Prey.new( :a ).satisfies? :b ).to be_falsy
27
+ end
28
+
29
+ it "can satisfy a module with a class" do
30
+ expect( prey.satisfies? Test::Prey::Mod ).to be_truthy
31
+ end
32
+
33
+ end
34
+
35
+ describe "traits" do
36
+
37
+ context "symbolic" do
38
+ let( :prey ){ Scorpion::Prey.new Test::Prey::Base, :apples }
39
+ it "satisfies matched traits" do
40
+ expect( prey.satisfies? Test::Prey::Base, :apples ).to be_truthy
41
+ end
42
+
43
+ it "doesn't satisfy mis-matched traits" do
44
+ expect( prey.satisfies? Test::Prey::Base, :oranges ).to be_falsy
45
+ end
46
+ end
47
+
48
+ context "module" do
49
+ let( :prey ){ Scorpion::Prey.new Test::Prey::Derived }
50
+
51
+ it "satisfies module traits" do
52
+ expect( prey.satisfies? Test::Prey::Base, Test::Prey::Derived ).to be_truthy
53
+ end
54
+ end
55
+
56
+ end
57
+
58
+ it "can satisfy symbol contracts" do
59
+ expect( Scorpion::Prey.new( :symbol ).satisfies? :symbol ).to be_truthy
60
+ end
61
+
62
+ it "satisfies ignores tail hash traits" do
63
+ expect( Scorpion::Prey.new( Test::Prey::Base ).satisfies?( Test::Prey::Base, ) )
64
+ end
65
+
66
+ describe "equality" do
67
+ let( :prey ) { Scorpion::Prey.new( Test::Prey::Derived ) }
68
+ let( :same ) { Scorpion::Prey.new( Test::Prey::Derived ) }
69
+ let( :different ) { Scorpion::Prey.new( Test::Prey::Base ) }
70
+
71
+ specify{ expect( prey ).to eq same }
72
+ specify{ expect( prey ).not_to eq different }
73
+ specify{ expect( prey.hash ).to eq same.hash }
74
+ end
75
+
76
+ end
@@ -0,0 +1,111 @@
1
+ require 'spec_helper'
2
+
3
+ module Test
4
+ module Nest
5
+ class Service; end
6
+ class Cache; end
7
+ class Guard; end
8
+ end
9
+ end
10
+
11
+ describe Scorpion::Rails::Controller, type: :controller do
12
+ controller ActionController::Base do
13
+ include Scorpion::Rails::Controller
14
+
15
+ feed_on do
16
+ service Test::Nest::Service
17
+ cache Test::Nest::Cache
18
+ end
19
+
20
+ def index
21
+ @guard1 = scorpion.hunt! Test::Nest::Guard
22
+ @guard2 = scorpion.hunt! Test::Nest::Guard
23
+ render nothing: true
24
+ end
25
+ end
26
+
27
+ context "basics" do
28
+ before( :each ) do
29
+ controller.class.scorpion_nest do
30
+ hunt_for Test::Nest::Guard # New each spawn
31
+ capture Test::Nest::Service # Once per request
32
+
33
+ share do
34
+ capture Test::Nest::Cache # Once for all requests
35
+ end
36
+ end
37
+
38
+ get :index
39
+ end
40
+
41
+ it "has a scorpion" do
42
+ expect( subject ).to respond_to :scorpion
43
+ end
44
+
45
+ it "initializes non-lazy dependencies" do
46
+ expect( subject.cache ).to be_present
47
+ end
48
+
49
+ it "spawns multiple guards" do
50
+ expect( assigns( :guard1 ) ).to be_present
51
+ expect( assigns( :guard2 ) ).to be_present
52
+ expect( assigns( :guard1 ) ).not_to eq assigns( :guard2 )
53
+ end
54
+
55
+ it "spawns a single cache for all requests" do
56
+ original_cache = subject.cache
57
+ get :index
58
+
59
+ expect( original_cache ).to be_present
60
+ expect( subject.cache ).to be original_cache
61
+ end
62
+
63
+ it "spawns the same service during the same request" do
64
+ allow( subject ).to receive( :index ) do
65
+ service = subject.service
66
+ expect( subject.scorpion.hunt! Test::Nest::Service ).to be service
67
+ controller.render nothing: true
68
+ end
69
+
70
+ get :index
71
+ end
72
+
73
+ it "spawns a different service each request" do
74
+ service = subject.service
75
+
76
+ allow( subject ).to receive( :index ) do
77
+ expect( subject.scorpion.hunt! Test::Nest::Service ).not_to be service
78
+ controller.render nothing: true
79
+ end
80
+
81
+ get :index
82
+ end
83
+
84
+ it "hunts for controller" do
85
+ allow( subject ).to receive( :index ) do
86
+ expect( subject.scorpion.hunt!( AbstractController::Base ) ).to be subject
87
+ controller.render nothing: true
88
+ end
89
+
90
+ get :index
91
+ end
92
+
93
+ it "hunts for response" do
94
+ allow( subject ).to receive( :index ) do
95
+ expect( subject.scorpion.hunt!( ActionDispatch::Response ) ).to be subject.response
96
+ controller.render nothing: true
97
+ end
98
+
99
+ get :index
100
+ end
101
+
102
+ it "hunts for request" do
103
+ allow( subject ).to receive( :index ) do
104
+ expect( subject.scorpion.hunt!( ActionDispatch::Request ).object_id ).to be subject.request.object_id
105
+ controller.render nothing: true
106
+ end
107
+
108
+ get :index
109
+ end
110
+ end
111
+ end
@@ -1,5 +1,4 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Scorpion do
4
-
5
4
  end
data/spec/spec_helper.rb CHANGED
@@ -5,7 +5,13 @@ if ENV['COVERAGE']
5
5
  else
6
6
  SimpleCov.start
7
7
  end
8
+ require 'pry'
9
+ require 'bundler/setup'
10
+ require 'combustion'
8
11
 
12
+ Combustion.initialize! :all
13
+
14
+ require 'rspec/rails'
9
15
  require 'scorpion'
10
16
 
11
17
  root_path = File.expand_path( "../..", __FILE__ )
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scorpion-ioc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Alexander
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-14 00:00:00.000000000 Z
11
+ date: 2015-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -66,6 +66,34 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.00'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.00'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.00'
83
+ - !ruby/object:Gem::Dependency
84
+ name: combustion
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.5.3
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.5.3
69
97
  description: Embrace convention over configuration while still benefitting from dependency
70
98
  injection design principles.
71
99
  email:
@@ -84,17 +112,46 @@ files:
84
112
  - Gemfile
85
113
  - Guardfile
86
114
  - LICENSE
87
- - Procfile
88
115
  - README.md
89
116
  - Rakefile
117
+ - circle.yml
118
+ - config.ru
90
119
  - lib/scorpion-ioc.rb
91
120
  - lib/scorpion.rb
121
+ - lib/scorpion/attribute.rb
122
+ - lib/scorpion/attribute_set.rb
123
+ - lib/scorpion/error.rb
124
+ - lib/scorpion/hunter.rb
125
+ - lib/scorpion/hunting_map.rb
126
+ - lib/scorpion/king.rb
127
+ - lib/scorpion/locale/en.yml
92
128
  - lib/scorpion/nest.rb
129
+ - lib/scorpion/prey.rb
130
+ - lib/scorpion/prey/builder_prey.rb
131
+ - lib/scorpion/prey/captured_prey.rb
132
+ - lib/scorpion/prey/class_prey.rb
133
+ - lib/scorpion/prey/hunted_prey.rb
134
+ - lib/scorpion/prey/module_prey.rb
93
135
  - lib/scorpion/rails.rb
94
- - lib/scorpion/rails/railtie.rb
136
+ - lib/scorpion/rails/controller.rb
95
137
  - lib/scorpion/version.rb
96
138
  - scorpion.gemspec
97
- - spec/lib/scorpion/scorpion.rb
139
+ - spec/internal/config/database.yml
140
+ - spec/internal/config/routes.rb
141
+ - spec/internal/db/combustion_test.sqlite
142
+ - spec/internal/db/schema.rb
143
+ - spec/internal/log/.gitignore
144
+ - spec/internal/public/favicon.ico
145
+ - spec/lib/scorpion/attribute_set_spec.rb
146
+ - spec/lib/scorpion/attribute_spec.rb
147
+ - spec/lib/scorpion/error_spec.rb
148
+ - spec/lib/scorpion/hunter_spec.rb
149
+ - spec/lib/scorpion/hunting_map_spec.rb
150
+ - spec/lib/scorpion/instance_spec.rb
151
+ - spec/lib/scorpion/king_spec.rb
152
+ - spec/lib/scorpion/prey/module_prey_spec.rb
153
+ - spec/lib/scorpion/prey_spec.rb
154
+ - spec/lib/scorpion/rails/controller_spec.rb
98
155
  - spec/lib/scorpion_spec.rb
99
156
  - spec/spec_helper.rb
100
157
  homepage: https://github.com/phallguy/scorpion
@@ -122,7 +179,22 @@ signing_key:
122
179
  specification_version: 4
123
180
  summary: Add IoC to rails with minimal fuss and ceremony
124
181
  test_files:
125
- - spec/lib/scorpion/scorpion.rb
182
+ - spec/internal/config/database.yml
183
+ - spec/internal/config/routes.rb
184
+ - spec/internal/db/combustion_test.sqlite
185
+ - spec/internal/db/schema.rb
186
+ - spec/internal/log/.gitignore
187
+ - spec/internal/public/favicon.ico
188
+ - spec/lib/scorpion/attribute_set_spec.rb
189
+ - spec/lib/scorpion/attribute_spec.rb
190
+ - spec/lib/scorpion/error_spec.rb
191
+ - spec/lib/scorpion/hunter_spec.rb
192
+ - spec/lib/scorpion/hunting_map_spec.rb
193
+ - spec/lib/scorpion/instance_spec.rb
194
+ - spec/lib/scorpion/king_spec.rb
195
+ - spec/lib/scorpion/prey/module_prey_spec.rb
196
+ - spec/lib/scorpion/prey_spec.rb
197
+ - spec/lib/scorpion/rails/controller_spec.rb
126
198
  - spec/lib/scorpion_spec.rb
127
199
  - spec/spec_helper.rb
128
200
  has_rdoc:
data/Procfile DELETED
@@ -1 +0,0 @@
1
- yard: sh -c 'rm -rf /tmp/scorpion_com_yardoc && yard server --reload'
@@ -1,15 +0,0 @@
1
- module Scorpion
2
- module Rails
3
-
4
- # # Automatically integrate Shog with the rails logger.
5
- # class Railtie < ::Rails::Railtie
6
- # config.before_initialize do
7
- # next if ::Rails.logger.formatter.class == Shog::Formatter
8
- # ::Rails.logger.formatter = Shog::Formatter.new.configure do
9
- # with :defaults
10
- # with :requests
11
- # end
12
- # end
13
- # end
14
- end
15
- end