forwarder19 0.2.0.rc3 → 0.2.0rc4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -403,7 +403,7 @@ A different helper can do this job without any ambiguity:
403
403
 
404
404
 
405
405
  ```ruby
406
- map( &applyto( :some_method ) )
406
+ map( &applying( :some_method ) )
407
407
  ```
408
408
 
409
409
  ### Commonly Used Pattern Helpers
@@ -63,6 +63,10 @@ module Forwarder
63
63
  @lambda
64
64
  end
65
65
 
66
+ def must_not_compile?
67
+ lambda? || aop? || custom_target?
68
+ end
69
+
66
70
  # This is always nil unless we are a custom_target, in which case
67
71
  # default is returned if target is :self, else target is returned
68
72
  def object_target default
@@ -6,11 +6,14 @@ module Forwarder
6
6
 
7
7
  def compile
8
8
  # Cannot compile because of intrinsic uncompilable traits of arguments
9
- # TODO: implement compilable inside arguments
10
- return unless !arguments.lambda? && !arguments.aop? && !arguments.custom_target?
9
+ return if arguments.must_not_compile?
10
+
11
11
  # Cannot compile because arguments cannot be compiled
12
12
  @compiled_args = Evaller.serialize arguments.args
13
+
14
+ # Cannot compile only because the arguments.args cannot be compiled
13
15
  return unless @compiled_args
16
+
14
17
  # Can compile :)))
15
18
  return compile_to_all if arguments.message.is_a? Array
16
19
  compile_one
@@ -5,6 +5,98 @@ module Forwarder
5
5
  attr_reader :arguments, :forwardee
6
6
 
7
7
 
8
+ # TODO: Break AOP out of this so that we do not check @ runtime
9
+ def forward
10
+ if arguments.aop?
11
+ forward_with_aop
12
+ else
13
+ forward_without_aop
14
+ end
15
+ end
16
+
17
+ def forward_chain
18
+ a = arguments
19
+ sr = symbolic_receiver
20
+ forwardee.module_eval do
21
+ define_method a.message do |*args, &blk|
22
+ args = a.before.(*args) if a.before?
23
+ tgt = a.target.inject( self ){ |r, sym| sr.( r, sym ) }
24
+ tgt.send( a.translation( a.message ), *a.complete_args(*args), &a.lambda( blk ) ).tap do | result |
25
+ break a.after.( result ) if a.after?
26
+ end
27
+ #.send( a.translation( a.message ), *a.complete_args(*args), &a.lambda( blk ) )
28
+ end
29
+ end
30
+ end
31
+
32
+ def forward_object
33
+ a = arguments
34
+ forwardee.module_eval do
35
+ define_method a.message do |*args, &blk|
36
+ args = a.before.(*args) if a.before?
37
+ a.object_target( self )
38
+ .send( a.translation( a.message ), *a.complete_args(*args), &a.lambda( blk ) ).tap do | result |
39
+ break a.after.( result ) if a.after?
40
+ end
41
+ end
42
+ end
43
+
44
+ end
45
+
46
+ private
47
+
48
+ def forward_with_aop
49
+ a = arguments
50
+ sr = symbolic_receiver
51
+ forwardee.module_eval do
52
+ define_method a.message do |*args, &blk|
53
+ args = a.before.(*args) if a.before?
54
+ sr
55
+ .( self, a.target )
56
+ .send( a.translation( a.message ), *a.complete_args(*args), &a.lambda( blk ) ).tap do | result |
57
+ break a.after.( result ) if a.after?
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+ def forward_without_aop
64
+ a = arguments
65
+ sr = symbolic_receiver
66
+ forwardee.module_eval do
67
+ define_method a.message do |*args, &blk|
68
+ sr
69
+ .( self, a.target )
70
+ .send( a.translation( a.message ), *a.complete_args(*args), &a.lambda( blk ) )
71
+ end
72
+ end
73
+ end
74
+
75
+ def initialize forwardee, arguments
76
+ @forwardee = forwardee
77
+ @arguments = arguments
78
+ end
79
+
80
+ def symbolic_receiver
81
+ @__symbolic_receiver__ = ->(rec, sym) do
82
+ case "#{sym}"
83
+ when /\A@/
84
+ rec.instance_variable_get sym
85
+ else
86
+ rec.send sym
87
+ end
88
+ end
89
+ end
90
+
91
+ end # class Meta
92
+ end # module Forwarder
93
+ module FForwarder
94
+ # I am the workerbee defining the methods and stuff
95
+ class Meta
96
+
97
+ attr_reader :arguments, :forwardee
98
+
99
+
8
100
  # TODO: Break AOP out of this so that we do not check @ runtime
9
101
  def forward
10
102
  a = arguments
@@ -24,59 +24,6 @@ module Forwarder
24
24
  compiler.compile
25
25
  end
26
26
 
27
- # def delegate
28
- # return unless arguments.delegatable?
29
- # delegate_to_forwardee
30
- # true
31
- # end
32
- #
33
- # def delegate_all
34
- # return unless arguments.all?
35
- # delegate_all_to_forwardee
36
- # true
37
- # end
38
- #
39
- # def delegate_all_to_forwardee
40
- # arguments.message.each do | msg |
41
- # forwardee.module_eval(
42
- # "def #{msg} *args, &blk; #{arguments.target}.#{msg}( *args, &blk ) end",
43
- # __FILE__,
44
- # __LINE__
45
- # )
46
- # end
47
- # end
48
- #
49
- #
50
- # def delegate_chain
51
- # return unless arguments.chain?
52
- # delegate_to_chain
53
- # true
54
- # end
55
- #
56
- # def delegate_to_chain
57
- # tltion = arguments.translation arguments.message
58
- # forwardee.module_eval(
59
- # "def #{arguments.message} *args, &blk; #{arguments.target.join(".")}.#{tltion}( *args, &blk ) end",
60
- # __FILE__,
61
- # __LINE__
62
- # )
63
- # end
64
- #
65
- # def delegate_object
66
- # return unless arguments.custom_target?
67
- # Meta.new( forwardee, arguments ).forward_object
68
- # true
69
- # end
70
- #
71
- # def delegate_to_forwardee
72
- # tltion = arguments.translation arguments.message
73
- # forwardee.module_eval(
74
- # "def #{arguments.message} *args, &blk; #{arguments.target}.#{tltion}( #{arguments.serialized_params}*args, &blk ) end",
75
- # __FILE__,
76
- # __LINE__
77
- # )
78
- # end
79
- #
80
27
  def initialize forwardee
81
28
  @forwardee = forwardee
82
29
  end
@@ -1,3 +1,3 @@
1
1
  module Forwarder
2
- VERSION = '0.2.0.rc3'
2
+ VERSION = '0.2.0rc4'
3
3
  end # module Forwarder
metadata CHANGED
@@ -1,30 +1,30 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forwarder19
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0.rc3
5
- prerelease: 6
4
+ version: 0.2.0rc4
5
+ prerelease: 5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Robert Dober
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-20 00:00:00.000000000Z
12
+ date: 2012-04-21 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: lab419_core
16
- requirement: &7941200 !ruby/object:Gem::Requirement
16
+ requirement: &19218520 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 0.0.1
21
+ version: 0.0.3
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *7941200
24
+ version_requirements: *19218520
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: ruby-debug19
27
- requirement: &7938300 !ruby/object:Gem::Requirement
27
+ requirement: &19214860 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0.11'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *7938300
35
+ version_requirements: *19214860
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &7789180 !ruby/object:Gem::Requirement
38
+ requirement: &19066140 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.9.2.2
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *7789180
46
+ version_requirements: *19066140
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &7124460 !ruby/object:Gem::Requirement
49
+ requirement: &18401500 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 2.9.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *7124460
57
+ version_requirements: *18401500
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: maruku
60
- requirement: &7119940 !ruby/object:Gem::Requirement
60
+ requirement: &18397100 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 0.6.0
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *7119940
68
+ version_requirements: *18397100
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: wirble
71
- requirement: &7118380 !ruby/object:Gem::Requirement
71
+ requirement: &18395760 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: 0.1.3
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *7118380
79
+ version_requirements: *18395760
80
80
  description: ! 'Ruby''s core Forwardable gets the job done(barely) and produces most
81
81
  unreadable code. Furthermore it is about twice as slow (1.9.2-p290) or thrice as
82
82
  slow (1.9.3-p0) as it needs to be.
@@ -104,7 +104,6 @@ files:
104
104
  - lib/forwarder.rb
105
105
  - lib/forwarder/evaller.rb
106
106
  - lib/forwarder/arguments.rb
107
- - lib/forwarder/helpers.rb
108
107
  - lib/forwarder/version.rb
109
108
  - lib/forwarder/params.rb
110
109
  - lib/forwarder/meta.rb
@@ -1,4 +0,0 @@
1
- require 'forwarder/helpers/proc'
2
- require 'forwarder/helpers/integer'
3
- require 'forwarder/helpers/kernel'
4
- require 'forwarder/helpers/object'