scorpion-ioc 0.5.13 → 0.5.14

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: 2707ee5f873ced43d6fcbbd383fc2d055dc71fb7
4
- data.tar.gz: de8955d86ecb98696c7734d89e539463aafe26a7
3
+ metadata.gz: 0f144ad2a3f2570fbb1e71ed99d52dd5b1cecc33
4
+ data.tar.gz: 08ff7b8a52474b70dc790596f5869312cda8846d
5
5
  SHA512:
6
- metadata.gz: ac6c07abf770a6d836d8031cc35dd1825e45066bbad7d0cc11077f2c5af2f492963e412f4fedfad5f3c5b8b9e8295ba7b6a84cb4fac45545a52e7efe3bd3cac4
7
- data.tar.gz: f2982774adc0dbe4ed94247917a5e869b8be1bf819e8da78103302bd9b9ca692b5ec44b7dfe8b3c10a0264382127c0df526bf79eec2adc248c2db95faacf15f3
6
+ metadata.gz: 4ac170a30e129bbdcac5aa5e2f29987a71604bdadd3bda1db63b890b2b86230708d14ccb49c85468eb056232ecba6a899f510395426bc292fb63554d909ffb40
7
+ data.tar.gz: 699520623d7dbe81f57de933e1a1fa571ee5371b06b63d67953fec8fae1eeb9628dcc412760bffe56564c356d3e6b2f5e0ef296adbda2122d878468ef581182e
data/README.md CHANGED
@@ -140,6 +140,9 @@ class Hunter
140
140
  depend_on do
141
141
  weapon Weapon
142
142
  end
143
+
144
+ # or
145
+ attr_dependency :weapon, Weapon
143
146
  end
144
147
  ```
145
148
 
@@ -168,17 +171,17 @@ hunter.weapon # => an Axe
168
171
  Overriding hunters!
169
172
 
170
173
  ```ruby
171
- class Axe < Weapon; end
172
- class Predator < Hunter; end
174
+ class Axe < Weapon; end
175
+ class Predator < Hunter; end
173
176
 
174
- scorpion.prepare do
175
- hunt_for Predator
176
- hunt_for Axe
177
- end
177
+ scorpion.prepare do
178
+ hunt_for Predator
179
+ hunt_for Axe
180
+ end
178
181
 
179
- hunter = scorpion.fetch Hunter
180
- hunter # => Predator
181
- hunter.weapon # => an Axe
182
+ hunter = scorpion.fetch Hunter
183
+ hunter # => Predator
184
+ hunter.weapon # => an Axe
182
185
  ```
183
186
 
184
187
 
@@ -210,10 +213,14 @@ end
210
213
  class Zoo
211
214
  include Scorpion::Object
212
215
 
213
- depend_on do # or #depend_on if you like
216
+ depend_on do
214
217
  keeper Zoo::Keeper
215
218
  vet Zoo::Vet, lazy: true
216
219
  end
220
+
221
+ # or with like attr_accessor
222
+ attr_dependency :keeper, Zook::Keeper
223
+ attr_dependency :vet, Zoo::Vet, lazy: true
217
224
  end
218
225
 
219
226
  zoo = scorpion.fetch Zoo
@@ -285,9 +292,9 @@ poker.poke # => "Sword"
285
292
 
286
293
  #### Traits
287
294
 
288
- Traits can be used to distinguish between dependency of the same type. For example
289
- a scorpion may be prepare to hunt for several weapons and the object needs a
290
- blunt weapon.
295
+ Traits can be used to distinguish between dependencies of the same type. For
296
+ example a scorpion may be prepared to hunt for several weapons and the object
297
+ needs a blunt weapon.
291
298
 
292
299
  ```ruby
293
300
  class Weapon; end
@@ -351,13 +358,14 @@ arguments.
351
358
  ```ruby
352
359
  class City
353
360
  def self.create( scorpion, name )
354
- klass = if name == "New York"
355
- BigCity
356
- else
357
- SmallCity
358
- end
361
+ klass =
362
+ if name == "New York"
363
+ BigCity
364
+ else
365
+ SmallCity
366
+ end
359
367
 
360
- klass.new name
368
+ scorpion.new klass, name
361
369
  end
362
370
 
363
371
  def initialize( name )
@@ -421,9 +429,9 @@ scorpion.fetch Logger # => Logger.new
421
429
  scorpion.fetch Logger # => Previously captured logger
422
430
  ```
423
431
 
424
- Captured dependencies are not shared with child scorpions (for example when
425
- conceiving scorpions from a [Nest](Nests)). To share captured dependency with children
426
- use `share`.
432
+ > Captured dependencies are not shared with child scorpions (for example when
433
+ > conceiving scorpions from a [Nest](Nests)). To share captured dependency with
434
+ > children use `share`.
427
435
 
428
436
  ### Nests
429
437
 
@@ -447,8 +455,8 @@ scorpion.fetch Logger # => Logger.new
447
455
 
448
456
  #### ActionController
449
457
 
450
- Scorpion provides simple integration into for rails controllers to establish
451
- a scorpion for each request.
458
+ Scorpion provides simple integration for rails controllers to establish a
459
+ scorpion for each request.
452
460
 
453
461
  ```ruby
454
462
  # user_service.rb
@@ -456,7 +464,7 @@ class UserService
456
464
  def find( username ) ... end
457
465
  end
458
466
 
459
- # config/nest.rb
467
+ # config/initializers/nest.rb
460
468
  require 'scorpion'
461
469
 
462
470
  Scorpion.prepare do
@@ -494,6 +502,11 @@ injection into ActiveJob objects.
494
502
 
495
503
  # avatar_job.rb
496
504
  class AvatarJob < ActiveJob::Base
505
+ depend_on do
506
+ users UserService, lazy: true
507
+ logger Logger
508
+ end
509
+
497
510
  def perform( id )
498
511
  user = users.find( id )
499
512
  logger.write "Found a user: #{ user }"
@@ -506,6 +519,9 @@ end
506
519
  Scorpion enhances ActiveRecord models to support resolving dependencies from
507
520
  a scorpion and sharing that scorpion with all associations.
508
521
 
522
+ > Consider using a SOA framework like [Shamu](https://github.com/phallguy/shamu)
523
+ > for managing complex resource relationships.
524
+
509
525
  ```ruby
510
526
  class User < ActiveRecord::Base
511
527
  depend_on do
@@ -518,7 +534,6 @@ class User < ActiveRecord::Base
518
534
  end
519
535
 
520
536
  class SessionsController < ActionController::Base
521
-
522
537
  def create
523
538
  user = User.with_scorpion( scorpion ).find params[:id]
524
539
  user = scorpion( User ).find params[:id]
@@ -542,3 +557,5 @@ end
542
557
  [The MIT License (MIT)](http://opensource.org/licenses/MIT)
543
558
 
544
559
  Copyright (c) 2015 Paul Alexander
560
+
561
+ [@phallguy](http://twitter.com/phallguy) / http://phallguy.com
@@ -64,6 +64,13 @@ module Scorpion
64
64
  traits.hash
65
65
  end
66
66
 
67
+ def inspect
68
+ result = "<#{ contract.inspect }"
69
+ result << " traits=#{ traits.to_a.inspect }" if traits.present?
70
+ result << ">"
71
+ result
72
+ end
73
+
67
74
  private
68
75
 
69
76
  # @return [Boolean] true if the pray satisfies the given contract.
@@ -64,5 +64,14 @@ module Scorpion
64
64
  dependency_map.reset
65
65
  end
66
66
 
67
+ # @return [String]
68
+ def inspect
69
+ dependencies = dependency_map.to_a
70
+ result = "<#{ self.class.name } contracts=#{ dependencies.inspect }"
71
+ result << " parent=#{ parent.inspect }" if parent
72
+ result << ">"
73
+ result
74
+ end
75
+
67
76
  end
68
77
  end
@@ -1,5 +1,5 @@
1
1
  module Scorpion
2
- VERSION_NUMBER = "0.5.13"
2
+ VERSION_NUMBER = "0.5.14"
3
3
  VERSION_SUFFIX = ""
4
4
  VERSION = "#{VERSION_NUMBER}#{VERSION_SUFFIX}"
5
5
  end
@@ -121,4 +121,10 @@ describe Scorpion::Hunter do
121
121
  end
122
122
  end
123
123
 
124
+ describe "#inspect" do
125
+ it "is helpful" do
126
+ expect( hunter.inspect ).to match /contracts/
127
+ expect( hunter.inspect ).not_to match /0x/
128
+ end
129
+ end
124
130
  end
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.5.13
4
+ version: 0.5.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Alexander
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-26 00:00:00.000000000 Z
11
+ date: 2016-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails