surrounded 0.2.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ffb676825adabf9eeb3f049b5bee0db872d4647
4
- data.tar.gz: 77088aade1c2e9079b07546681e8e1997b7aab1c
3
+ metadata.gz: 004d807c4309fea2abc8847f5c23aba8994f6829
4
+ data.tar.gz: 3a42c0a074f5b1e3f179eb3763ab21a36afbcc19
5
5
  SHA512:
6
- metadata.gz: 2a890fa34e1b6ebd9c1f6646f2fb5d0ea2ea6992e7b8d9a63d84d023267eb2ea1e9898e808ec98ece3995cea8e801a5bfc9da3f4da108cbb3445b336c40b1eb2
7
- data.tar.gz: 439627c4612ddfade5819fe832a1799127d179a50ca92fa386efadf60ea51f31a2c9fcbd487581182831eda7ddbee4a8f57cdcb367a3c4cb667cdd44e92e35c0
6
+ metadata.gz: 59292a0a8d86b9703e2364df3416613af3ab18695ee6afa064b4597f57c3c0489e0c551bebe00edc6d19b8d9c618f541d78aec23dbc42cc9d81e9f9b9e448755
7
+ data.tar.gz: f4eb083c7d739c79967aef23e57436770eaadc16ea6a1b30b19cd5a0e8eb59c1a521c7d3733cec411b77b97363426409990b012a5c8b9afd4abe1c194af8208d
@@ -17,6 +17,13 @@ module Surrounded
17
17
 
18
18
  private
19
19
 
20
+ def wrap(name, &block)
21
+ require 'delegate'
22
+ wrapper_name = name.to_s.gsub(/(?:^|_)([a-z])/){ $1.upcase }
23
+ klass = const_set(wrapper_name, Class.new(SimpleDelegator, &block))
24
+ klass.send(:include, Surrounded)
25
+ end
26
+
20
27
  def apply_roles_on(which)
21
28
  @policy = which
22
29
  end
@@ -24,20 +31,13 @@ module Surrounded
24
31
  def initialize(*setup_args)
25
32
  private_attr_reader(*setup_args)
26
33
 
27
- # I want this to work so I can set the arity on initialize:
28
- # class_eval %Q<
29
- # def initialize(#{*setup_args})
30
- # arguments = parameters.map{|arg| eval(arg[1].to_s) }
31
- # map_roles(setup_args.zip(arguments))
32
- # apply_roles if policy == :initialize
33
- # end
34
- # >
35
-
36
- define_method(:initialize){ |*args|
37
- map_roles(setup_args.zip(args))
38
-
39
- apply_roles if policy == :initialize
40
- }
34
+ class_eval "
35
+ def initialize(#{setup_args.join(',')})
36
+ arguments = method(__method__).parameters.map{|arg| eval(arg[1].to_s) }
37
+ map_roles(#{setup_args}.zip(arguments))
38
+ apply_roles if policy == :initialize
39
+ end
40
+ "
41
41
  end
42
42
 
43
43
  def private_attr_reader(*method_names)
@@ -1,3 +1,3 @@
1
1
  module Surrounded
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
data/lib/surrounded.rb CHANGED
@@ -54,7 +54,7 @@ module Surrounded
54
54
  !!context.role?(meth){} || super
55
55
  end
56
56
 
57
- class NullContext < BasicObject
57
+ class NullContext
58
58
  def role?(*args)
59
59
  nil
60
60
  end
@@ -1,15 +1,13 @@
1
1
  require 'test_helper'
2
2
 
3
3
  # If you want to use wrappers, here's how you could
4
- require 'delegate'
5
4
  class WrapperContext
6
5
  extend Surrounded::Context
7
6
 
8
7
  apply_roles_on(:trigger)
9
- setup(:admin, :task)
8
+ initialize(:admin, :task)
10
9
 
11
- class Admin < SimpleDelegator
12
- include Surrounded
10
+ wrap :admin do
13
11
  def some_admin_method
14
12
  'hello from the admin wrapper!'
15
13
  end
@@ -119,7 +119,6 @@ end
119
119
 
120
120
  describe Surrounded::Context, '.setup' do
121
121
  it 'defines an initialize method accepting the same arguments' do
122
- skip "not yet implemented. may not be possible"
123
122
  assert_equal 2, RoleAssignmentContext.instance_method(:initialize).arity
124
123
  end
125
124
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: surrounded
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - '''Jim Gay'''
@@ -109,4 +109,3 @@ test_files:
109
109
  - test/surrounded_context_test.rb
110
110
  - test/surrounded_test.rb
111
111
  - test/test_helper.rb
112
- has_rdoc: