surrounded 0.9.3 → 0.9.4

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: 03f2358dca677e952ee8a0fd5887d309f7156ac2
4
- data.tar.gz: eb183b1de9c4e2226a4c4228f78b6a692fe80810
3
+ metadata.gz: 63bac757a4c7f7b9cb953a51123e31dc3612fa22
4
+ data.tar.gz: 1afa12d700b0756ce4e22becf4555169d8e4fa10
5
5
  SHA512:
6
- metadata.gz: f875e9a9bad6f5a24a199e2b04ad32be237affa9500bc3cc870ad2206cc5191658c8bdfb92b08cc044b84d2e1fd9ada1392003e0ed90a6f316d3b9ab82d6bf33
7
- data.tar.gz: b7118a9f177ab1b0e6a1c609c412bc3de832b312d97a6c2054f08fe758b5f1864f6f2cf332e63160f490baee89fdedf90a2b7eb537753387ec4279f20b3ef51f
6
+ metadata.gz: 4d508948a224105b736246b96f0a0a8dec5d9bccd9f2000429071135481fe09a3ecac7963e37e684940411a1d02bf89f5697810593469acbc47b7013e4a95820
7
+ data.tar.gz: 1f68568474713853a086aef3c3e09ce292fbd66dca77c00c68f32afe11a30af593d159ba76c56f31765dd049063646b214f0bf556a302f9fd07be242274f4db1
data/.codeclimate.yml ADDED
@@ -0,0 +1,4 @@
1
+ languages:
2
+ Ruby: true
3
+ exclude_paths:
4
+ - "examples"
data/.travis.yml CHANGED
@@ -2,8 +2,8 @@ language: ruby
2
2
  cache: bundler
3
3
  rvm:
4
4
  - 2.0.0
5
- - 2.1.1
6
- - 2.2.0
5
+ - 2.1.5
6
+ - 2.2.2
7
7
  - ruby-head
8
8
  - jruby-head
9
9
  - rbx
@@ -11,6 +11,7 @@ env:
11
11
  - COVERALLS=true
12
12
  matrix:
13
13
  allow_failures:
14
+ - rvm: 2.0.0
14
15
  - rvm: ruby-head
15
16
  - rvm: jruby-head
16
17
  - rvm: rbx
data/README.md CHANGED
@@ -53,6 +53,24 @@ There are 2 things left to do:
53
53
  1. define behaviors for each role and
54
54
  2. define how you can trigger their actions
55
55
 
56
+ Currently initializing contexts does not require the use of keyword arguments, _but it will in the future_.
57
+
58
+ You should consider using explicit names when initialize now by using `keyword_initialize`:
59
+
60
+ ```ruby
61
+ class Employment
62
+ extend Surrounded::Context
63
+
64
+ keyword_initialize :employee, :boss
65
+ end
66
+
67
+ user1 = User.find(1)
68
+ user2 = User.find(2)
69
+ context = Employment.new(employee: user1, boss: user2)
70
+ ```
71
+
72
+ This will allow you to prepare your accessing code to use keywords.
73
+
56
74
  ## Defining behaviors for roles
57
75
 
58
76
  Behaviors for your roles are easily defined just like you define a method. Provide your role a block and define methods there.
@@ -30,7 +30,7 @@ module Surrounded
30
30
 
31
31
  def define_access_method(name, &block)
32
32
  mod = Module.new
33
- num = __LINE__; mod.class_eval {
33
+ mod.class_eval {
34
34
  define_method "disallow_#{name}?" do
35
35
  begin
36
36
  apply_behaviors
@@ -3,8 +3,8 @@ module Surrounded
3
3
  module Forwarding
4
4
  def forward_trigger(receiver, message, alternate=message)
5
5
  raise(ArgumentError, %{you may not forward '%{m}`} % {m: message}) if ['__id__','__send__'].include?(message.to_s)
6
- trigger alternate do
7
- self.send(receiver).public_send(message)
6
+ trigger alternate do |*args, &block|
7
+ self.send(receiver).public_send(message,*args, &block)
8
8
  end
9
9
  end
10
10
 
@@ -3,7 +3,7 @@ module Surrounded
3
3
  module Initializing
4
4
  # Shorthand for creating an instance level initialize method which
5
5
  # handles the mapping of the given arguments to their named role.
6
- def initialize(*setup_args)
6
+ def initialize_without_keywords(*setup_args)
7
7
  private_attr_reader(*setup_args)
8
8
 
9
9
  mod = Module.new
@@ -17,6 +17,11 @@ module Surrounded
17
17
  const_set("ContextInitializer", mod)
18
18
  include mod
19
19
  end
20
+ def initialize(*setup_args)
21
+ warn "Deprecated: The behavior of 'initialize' will require keywords in the future
22
+ Consider using keyword arguments or switching to 'initialize_without_keywords'\n\n"
23
+ initialize_without_keywords(*setup_args)
24
+ end
20
25
 
21
26
  def keyword_initialize(*setup_args)
22
27
  private_attr_reader(*setup_args)
@@ -1,5 +1,5 @@
1
1
  module Surrounded
2
- VERSION = "0.9.3"
2
+ VERSION = "0.9.4"
3
3
 
4
4
  def self.version
5
5
  VERSION
@@ -7,6 +7,8 @@ class Sending
7
7
 
8
8
  forwarding [:hello, :goodbye] => :one
9
9
  forward_trigger :two, :ping
10
+ forward_trigger :two, :argumentative
11
+ forwards :two, :blockhead
10
12
 
11
13
  role :one do
12
14
  def hello
@@ -22,6 +24,14 @@ class Sending
22
24
  def ping
23
25
  one.hello
24
26
  end
27
+
28
+ def argumentative(yes, no)
29
+ [yes, no].join(' and ')
30
+ end
31
+
32
+ def blockhead
33
+ yield
34
+ end
25
35
  end
26
36
  end
27
37
 
@@ -56,4 +66,15 @@ describe Surrounded::Context, 'forwarding triggers' do
56
66
  }
57
67
  assert_match(/you may not forward '__send__/i, error.message)
58
68
  end
69
+
70
+ it 'passes arguments' do
71
+ assert_equal 'YES and NO', context.argumentative('YES','NO')
72
+ end
73
+
74
+ it 'passes blocks' do
75
+ result = context.blockhead do
76
+ "Put them in the iron maiden. Excellent!"
77
+ end
78
+ assert_equal "Put them in the iron maiden. Excellent!", result
79
+ end
59
80
  end
@@ -65,7 +65,7 @@ describe ProxyContext do
65
65
  it 'passes missing methods up the ancestry of the object' do
66
66
  err = ->{ context.admin_missing_method }.must_raise(NoMethodError)
67
67
 
68
- assert_match /ProxyUser.*name="Jim"/, err.message
68
+ assert_match(/ProxyUser.*name="Jim"/, err.message)
69
69
  end
70
70
 
71
71
  it 'allows access to other objects in the context' do
@@ -259,21 +259,25 @@ describe Surrounded::Context, 'auto-assigning roles for collections' do
259
259
  end
260
260
  end
261
261
 
262
- class Keyworder
263
- extend Surrounded::Context
264
-
265
- keyword_initialize :this, :that
266
- end
262
+ begin
263
+ class Keyworder
264
+ extend Surrounded::Context
267
265
 
268
- describe Surrounded::Context, 'keyword initializers' do
269
- it 'works with keyword arguments' do
270
- assert context = Keyworder.new(this: User.new('Jim'), that: User.new('Guille'))
266
+ keyword_initialize :this, :that
271
267
  end
272
268
 
273
- it 'raises errors with missing keywords' do
274
- err = assert_raises(ArgumentError){
275
- Keyworder.new(this: User.new('Amy'))
276
- }
277
- assert_match /missing keyword: that/, err.message
269
+ describe Surrounded::Context, 'keyword initializers' do
270
+ it 'works with keyword arguments' do
271
+ assert Keyworder.new(this: User.new('Jim'), that: User.new('Guille'))
272
+ end
273
+
274
+ it 'raises errors with missing keywords' do
275
+ err = assert_raises(ArgumentError){
276
+ Keyworder.new(this: User.new('Amy'))
277
+ }
278
+ assert_match(/missing keyword: that/, err.message)
279
+ end
278
280
  end
281
+ rescue SyntaxError
282
+ STDOUT.puts "No support for keywords"
279
283
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: surrounded
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - "'Jim Gay'"
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-14 00:00:00.000000000 Z
11
+ date: 2015-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: triad
@@ -59,6 +59,7 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
+ - ".codeclimate.yml"
62
63
  - ".gitignore"
63
64
  - ".simplecov"
64
65
  - ".travis.yml"