mixit 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -41,9 +41,11 @@ __1.__
41
41
 
42
42
  Temporarily mix 'SomeModule' onto 'self' (non-thread safe).
43
43
 
44
- Mixit.temporarily :modules => [SomeModule], :scope => self do
45
- p self.class # => Object
46
- p respond_to?(:some_mixed_method) # => true
44
+ Mixit.new :modules => [SomeModule], :scope => self do |mix|
45
+ mix.temporarily do
46
+ p self.class # => Object
47
+ p respond_to?(:some_mixed_method) # => true
48
+ end
47
49
  end
48
50
 
49
51
  p self.class # => Object
@@ -60,9 +62,11 @@ to the original scope.
60
62
 
61
63
  You should be careful, as always.
62
64
 
63
- Mixit.temporarily :modules => [SomeModule], :scope => self do |extended|
64
- p extended.class # => Object
65
- p extended.respond_to?(:some_mixed_method) # => true
65
+ Mixit.new :modules => [SomeModule], :scope => self do |mix|
66
+ mix.temporarily do |extended|
67
+ p extended.class # => Object
68
+ p extended.respond_to?(:some_mixed_method) # => true
69
+ end
66
70
  end
67
71
 
68
72
 
@@ -1,35 +1,10 @@
1
1
  require "mixit/version"
2
2
 
3
3
  class Mixit
4
-
5
- class << self
6
- #
7
- # Temporarily extends a scope with instance methods from module(s).
8
- #
9
- # @param opts
10
- # (see Mixit#initialize)
11
- #
12
- # @option opts
13
- # (see Mixit#initialize)
14
- #
15
- # @param block
16
- # (see Mixit#temporarily)
17
- #
18
- # @yieldparam object
19
- # (see Mixit#temporarily)
20
- #
21
- # @return
22
- # (see Mixit#temporarily)
23
- #
24
- def temporarily opts, &block
25
- mixit = new(opts)
26
- mixit.temporarily(&block)
27
- end
28
- end
29
-
4
+
30
5
  #
31
6
  # @return [Array<Module>]
32
- # An Array of modules to extend a scope with.
7
+ # A list of modules to extend a scope with.
33
8
  #
34
9
  attr_reader :modules
35
10
 
@@ -41,13 +16,15 @@ class Mixit
41
16
 
42
17
  #
43
18
  # @param [Hash] opts
44
- # A Hash of options.
19
+ # A key -> value pair of options.
45
20
  #
46
21
  # @option opts [Object] :scope
47
22
  # The scope to extend.
48
23
  #
49
24
  # @option opts [Module] :modules
50
- # An Array of modules to extend a scope with.
25
+ # A list of modules to extend the scope with.
26
+ #
27
+ # @yieldparam [Mixit] _self
51
28
  #
52
29
  def initialize opts
53
30
  @clones = []
@@ -61,6 +38,10 @@ class Mixit
61
38
  else
62
39
  @scope = opts[:scope]
63
40
  end
41
+
42
+ if block_given?
43
+ yield(self)
44
+ end
64
45
  end
65
46
 
66
47
  #
@@ -1,3 +1,3 @@
1
1
  class Mixit
2
- VERSION = '0.5.1'
2
+ VERSION = '0.5.2'
3
3
  end
@@ -13,8 +13,10 @@ context Mixit do
13
13
  it 'must provide access to mixed-in methods' do
14
14
  block = proc { }
15
15
 
16
- Mixit.temporarily :modules => [@module], :scope => block do
17
- callme.must_equal(:ok)
16
+ Mixit.new :modules => [@module], :scope => block do |mix|
17
+ mix.temporarily do
18
+ callme.must_equal(:ok)
19
+ end
18
20
  end
19
21
  end
20
22
 
@@ -22,8 +24,10 @@ context Mixit do
22
24
  block = proc { }
23
25
  local = :ok
24
26
 
25
- Mixit.temporarily :modules => [@module], :scope => block do
26
- local.must_equal(:ok)
27
+ Mixit.new :modules => [@module], :scope => block do |mix|
28
+ mix.temporarily do
29
+ local.must_equal(:ok)
30
+ end
27
31
  end
28
32
  end
29
33
 
@@ -31,8 +35,10 @@ context Mixit do
31
35
  def callme_() :ok end
32
36
  block = proc { }
33
37
 
34
- Mixit.temporarily :modules => [@module], :scope => block do
35
- callme_.must_equal(:ok)
38
+ Mixit.new :modules => [@module], :scope => block do |mix|
39
+ mix.temporarily do
40
+ callme_.must_equal(:ok)
41
+ end
36
42
  end
37
43
  end
38
44
 
@@ -45,8 +51,10 @@ context Mixit do
45
51
  end
46
52
  end
47
53
 
48
- Mixit.temporarily :modules => [@module], :scope => block do
49
- @ok = :no
54
+ Mixit.new :modules => [@module], :scope => block do |mix|
55
+ mix.temporarily do
56
+ @ok = :no
57
+ end
50
58
  end
51
59
 
52
60
  instance_variable_defined?(:@ok).must_equal(false)
@@ -55,8 +63,8 @@ context Mixit do
55
63
  it 'must remove methods added by mixed-in modules.' do
56
64
  block = proc {}
57
65
 
58
- Mixit.temporarily :modules => [@module], :scope => block do
59
- nil
66
+ Mixit.new :modules => [@module], :scope => block do |mix|
67
+ mix.temporarily { nil }
60
68
  end
61
69
 
62
70
  respond_to?(:callme).must_equal(false)
@@ -67,16 +75,20 @@ context Mixit do
67
75
  it 'must provide access to mixed-in methods.' do
68
76
  block = proc {}
69
77
 
70
- Mixit.temporarily :modules => [@module], :scope => block do |receiver|
71
- receiver.callme.must_equal(:ok)
78
+ Mixit.new :modules => [@module], :scope => block do |mix|
79
+ mix.temporarily do |extended|
80
+ extended.callme.must_equal(:ok)
81
+ end
72
82
  end
73
83
  end
74
84
 
75
85
  it 'must not extend the original receiver with mixed-in methods.' do
76
86
  block = proc {}
77
87
 
78
- Mixit.temporarily :modules => [@module], :scope => block do |receiver|
79
- respond_to?(:callme).must_equal(false)
88
+ Mixit.new :modules => [@module], :scope => block do |mix|
89
+ mix.temporarily do |extended|
90
+ respond_to?(:callme).must_equal(false)
91
+ end
80
92
  end
81
93
  end
82
94
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mixit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-01 00:00:00.000000000 Z
12
+ date: 2011-12-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &70360248249540 !ruby/object:Gem::Requirement
16
+ requirement: &70148116454580 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.9.2
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70360248249540
24
+ version_requirements: *70148116454580
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: minitest
27
- requirement: &70360248249040 !ruby/object:Gem::Requirement
27
+ requirement: &70148116454080 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '2.5'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70360248249040
35
+ version_requirements: *70148116454080
36
36
  description: Temporarily extend the calling scope of a block with instance methods
37
37
  from a module.
38
38
  email:
@@ -67,7 +67,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
67
67
  version: '0'
68
68
  segments:
69
69
  - 0
70
- hash: 287058587748482884
70
+ hash: -362045613105573615
71
71
  required_rubygems_version: !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
@@ -76,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
76
  version: '0'
77
77
  segments:
78
78
  - 0
79
- hash: 287058587748482884
79
+ hash: -362045613105573615
80
80
  requirements: []
81
81
  rubyforge_project: mixit
82
82
  rubygems_version: 1.8.11