caricature 0.7.2 → 0.7.5
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.
- data/README.rdoc +97 -97
- data/Rakefile +310 -310
- data/caricature.gemspec +110 -106
- data/lib/caricature.rb +3 -1
- data/lib/caricature/bacon.rb +2 -2
- data/lib/caricature/bacon/integration.rb +75 -55
- data/lib/caricature/clr.rb +4 -3
- data/lib/caricature/clr/aspnet_mvc.rb +3 -3
- data/lib/caricature/clr/descriptor.rb +106 -39
- data/lib/caricature/clr/event_verification.rb +57 -0
- data/lib/caricature/clr/expectation.rb +101 -0
- data/lib/caricature/clr/isolation.rb +49 -13
- data/lib/caricature/clr/isolator.rb +141 -5
- data/lib/caricature/clr/messenger.rb +6 -0
- data/lib/caricature/clr/method_call_recorder.rb +97 -0
- data/lib/caricature/core_ext.rb +11 -0
- data/lib/{core_ext → caricature/core_ext}/array.rb +0 -0
- data/lib/{core_ext → caricature/core_ext}/class.rb +0 -0
- data/lib/{core_ext → caricature/core_ext}/hash.rb +0 -0
- data/lib/{core_ext → caricature/core_ext}/module.rb +0 -0
- data/lib/{core_ext → caricature/core_ext}/object.rb +0 -0
- data/lib/{core_ext → caricature/core_ext}/string.rb +0 -0
- data/lib/{core_ext → caricature/core_ext}/system/string.rb +0 -0
- data/lib/{core_ext → caricature/core_ext}/system/type.rb +6 -0
- data/lib/caricature/expectation.rb +108 -66
- data/lib/caricature/isolator.rb +3 -3
- data/lib/caricature/method_call_recorder.rb +32 -4
- data/lib/caricature/rspec/integration.rb +118 -77
- data/lib/caricature/version.rb +5 -5
- data/spec/bacon/integration/callback_spec.rb +156 -156
- data/spec/bacon/integration/clr_to_clr_spec.rb +1 -2
- data/spec/bacon/integration/event_spec.rb +98 -0
- data/spec/bacon/integration/indexer_spec.rb +1 -1
- data/spec/bacon/spec_helper.rb +4 -4
- data/spec/bacon/unit/descriptor_spec.rb +95 -42
- data/spec/bacon/unit/expectation_spec.rb +2 -2
- data/spec/bacon/unit/interop_spec.rb +1 -14
- data/spec/bacon/unit/isolation_spec.rb +1 -1
- data/spec/bacon/unit/isolator_spec.rb +5 -5
- data/spec/bin/ClrModels.dll +0 -0
- data/spec/models/ClrModels.cs +32 -8
- data/spec/models/ruby_models.rb +150 -150
- data/spec/rspec/integration/callback_spec.rb +156 -156
- data/spec/rspec/integration/indexer_spec.rb +1 -1
- data/spec/rspec/spec_helper.rb +12 -6
- data/spec/rspec/unit/descriptor_spec.rb +93 -42
- data/spec/rspec/unit/event_spec.rb +17 -0
- data/spec/rspec/unit/interop_spec.rb +0 -13
- data/spec/spec_helper.rb +14 -14
- metadata +20 -22
- data/lib/core_ext/core_ext.rb +0 -8
- data/spec/bin/ClrModels.dll.mdb +0 -0
data/caricature.gemspec
CHANGED
@@ -1,107 +1,111 @@
|
|
1
|
-
# WARNING : RAKE AUTO-GENERATED FILE. DO NOT MANUALLY EDIT!
|
2
|
-
# RUN : 'rake gem:update_gemspec'
|
3
|
-
|
4
|
-
Gem::Specification.new do |s|
|
5
|
-
s.authors = ["Ivan Porto Carrero"]
|
6
|
-
s.bindir = "bin"
|
7
|
-
s.add_dependency "uuidtools", ">= 2.0.0, runtime"
|
8
|
-
s.description = "Caricature brings simple mocking to Ruby, DLR and CLR."
|
9
|
-
s.email = "ivan@flanders.co.nz"
|
10
|
-
s.extra_rdoc_files = ["README.rdoc"]
|
11
|
-
s.files = ["README.rdoc",
|
12
|
-
"Rakefile",
|
13
|
-
"caricature.gemspec",
|
14
|
-
"lib/caricature",
|
15
|
-
"lib/caricature.rb",
|
16
|
-
"lib/caricature/bacon",
|
17
|
-
"lib/caricature/bacon.rb",
|
18
|
-
"lib/caricature/bacon/integration.rb",
|
19
|
-
"lib/caricature/clr",
|
20
|
-
"lib/caricature/clr.rb",
|
21
|
-
"lib/caricature/clr/aspnet_mvc.rb",
|
22
|
-
"lib/caricature/clr/descriptor.rb",
|
23
|
-
"lib/caricature/clr/
|
24
|
-
"lib/caricature/clr/
|
25
|
-
"lib/caricature/clr/
|
26
|
-
"lib/caricature/
|
27
|
-
"lib/caricature/
|
28
|
-
"lib/caricature/
|
29
|
-
"lib/caricature/
|
30
|
-
"lib/caricature/
|
31
|
-
"lib/caricature/
|
32
|
-
"lib/caricature/
|
33
|
-
"lib/caricature/
|
34
|
-
"lib/caricature/
|
35
|
-
"lib/caricature/
|
36
|
-
"lib/caricature/
|
37
|
-
"lib/core_ext",
|
38
|
-
"lib/core_ext/
|
39
|
-
"lib/core_ext/
|
40
|
-
"lib/
|
41
|
-
"lib/
|
42
|
-
"lib/
|
43
|
-
"lib/
|
44
|
-
"lib/
|
45
|
-
"lib/
|
46
|
-
"lib/
|
47
|
-
"lib/
|
48
|
-
"
|
49
|
-
"
|
50
|
-
"
|
51
|
-
"spec/bacon
|
52
|
-
"spec/bacon/integration
|
53
|
-
"spec/bacon/integration/
|
54
|
-
"spec/bacon/integration/
|
55
|
-
"spec/bacon/
|
56
|
-
"spec/bacon/
|
57
|
-
"spec/bacon/
|
58
|
-
"spec/bacon/
|
59
|
-
"spec/bacon/
|
60
|
-
"spec/bacon/unit
|
61
|
-
"spec/bacon/unit/
|
62
|
-
"spec/bacon/unit/
|
63
|
-
"spec/bacon/unit/
|
64
|
-
"spec/bacon/unit/
|
65
|
-
"spec/bacon/unit/
|
66
|
-
"spec/bacon/unit/
|
67
|
-
"spec/
|
68
|
-
"spec/
|
69
|
-
"spec/
|
70
|
-
"spec/
|
71
|
-
"spec/
|
72
|
-
"spec/
|
73
|
-
"spec/
|
74
|
-
"spec/
|
75
|
-
"spec/
|
76
|
-
"spec/rspec
|
77
|
-
"spec/rspec/integration
|
78
|
-
"spec/rspec/integration/
|
79
|
-
"spec/rspec/integration/
|
80
|
-
"spec/rspec/
|
81
|
-
"spec/rspec/
|
82
|
-
"spec/rspec/
|
83
|
-
"spec/rspec/
|
84
|
-
"spec/rspec/unit
|
85
|
-
"spec/rspec/unit/
|
86
|
-
"spec/rspec/unit/
|
87
|
-
"spec/rspec/unit/
|
88
|
-
"spec/rspec/unit/
|
89
|
-
"spec/rspec/unit/
|
90
|
-
"spec/rspec/unit/
|
91
|
-
"spec/rspec/unit/
|
92
|
-
"spec/
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
s.
|
98
|
-
s.
|
99
|
-
s.
|
100
|
-
s.
|
101
|
-
s.
|
102
|
-
s.
|
103
|
-
s.
|
104
|
-
s.
|
105
|
-
s.
|
106
|
-
s.
|
1
|
+
# WARNING : RAKE AUTO-GENERATED FILE. DO NOT MANUALLY EDIT!
|
2
|
+
# RUN : 'rake gem:update_gemspec'
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.authors = ["Ivan Porto Carrero"]
|
6
|
+
s.bindir = "bin"
|
7
|
+
s.add_dependency "uuidtools", ">= 2.0.0, runtime"
|
8
|
+
s.description = "Caricature brings simple mocking to Ruby, DLR and CLR."
|
9
|
+
s.email = "ivan@flanders.co.nz"
|
10
|
+
s.extra_rdoc_files = ["README.rdoc"]
|
11
|
+
s.files = ["README.rdoc",
|
12
|
+
"Rakefile",
|
13
|
+
"caricature.gemspec",
|
14
|
+
"lib/caricature",
|
15
|
+
"lib/caricature.rb",
|
16
|
+
"lib/caricature/bacon",
|
17
|
+
"lib/caricature/bacon.rb",
|
18
|
+
"lib/caricature/bacon/integration.rb",
|
19
|
+
"lib/caricature/clr",
|
20
|
+
"lib/caricature/clr.rb",
|
21
|
+
"lib/caricature/clr/aspnet_mvc.rb",
|
22
|
+
"lib/caricature/clr/descriptor.rb",
|
23
|
+
"lib/caricature/clr/event_verification.rb",
|
24
|
+
"lib/caricature/clr/expectation.rb",
|
25
|
+
"lib/caricature/clr/isolation.rb",
|
26
|
+
"lib/caricature/clr/isolator.rb",
|
27
|
+
"lib/caricature/clr/messenger.rb",
|
28
|
+
"lib/caricature/clr/method_call_recorder.rb",
|
29
|
+
"lib/caricature/core_ext",
|
30
|
+
"lib/caricature/core_ext.rb",
|
31
|
+
"lib/caricature/core_ext/array.rb",
|
32
|
+
"lib/caricature/core_ext/class.rb",
|
33
|
+
"lib/caricature/core_ext/hash.rb",
|
34
|
+
"lib/caricature/core_ext/module.rb",
|
35
|
+
"lib/caricature/core_ext/object.rb",
|
36
|
+
"lib/caricature/core_ext/string.rb",
|
37
|
+
"lib/caricature/core_ext/system",
|
38
|
+
"lib/caricature/core_ext/system/string.rb",
|
39
|
+
"lib/caricature/core_ext/system/type.rb",
|
40
|
+
"lib/caricature/descriptor.rb",
|
41
|
+
"lib/caricature/expectation.rb",
|
42
|
+
"lib/caricature/isolation.rb",
|
43
|
+
"lib/caricature/isolator.rb",
|
44
|
+
"lib/caricature/messenger.rb",
|
45
|
+
"lib/caricature/method_call_recorder.rb",
|
46
|
+
"lib/caricature/rspec",
|
47
|
+
"lib/caricature/rspec.rb",
|
48
|
+
"lib/caricature/rspec/integration.rb",
|
49
|
+
"lib/caricature/verification.rb",
|
50
|
+
"lib/caricature/version.rb",
|
51
|
+
"spec/bacon",
|
52
|
+
"spec/bacon/integration",
|
53
|
+
"spec/bacon/integration/callback_spec.rb",
|
54
|
+
"spec/bacon/integration/clr_to_clr_spec.rb",
|
55
|
+
"spec/bacon/integration/clr_to_ruby_spec.rb",
|
56
|
+
"spec/bacon/integration/event_spec.rb",
|
57
|
+
"spec/bacon/integration/indexer_spec.rb",
|
58
|
+
"spec/bacon/integration/ruby_to_ruby_spec.rb",
|
59
|
+
"spec/bacon/spec_helper.rb",
|
60
|
+
"spec/bacon/unit",
|
61
|
+
"spec/bacon/unit/core_ext_spec.rb",
|
62
|
+
"spec/bacon/unit/descriptor_spec.rb",
|
63
|
+
"spec/bacon/unit/expectation_spec.rb",
|
64
|
+
"spec/bacon/unit/interop_spec.rb",
|
65
|
+
"spec/bacon/unit/isolation_spec.rb",
|
66
|
+
"spec/bacon/unit/isolator_spec.rb",
|
67
|
+
"spec/bacon/unit/messaging_spec.rb",
|
68
|
+
"spec/bacon/unit/method_call_spec.rb",
|
69
|
+
"spec/bacon/unit/sword_spec.rb",
|
70
|
+
"spec/bacon/unit/verification_spec.rb",
|
71
|
+
"spec/bin",
|
72
|
+
"spec/bin/ClrModels.dll",
|
73
|
+
"spec/models",
|
74
|
+
"spec/models/ClrModels.cs",
|
75
|
+
"spec/models/ruby_models.rb",
|
76
|
+
"spec/rspec",
|
77
|
+
"spec/rspec/integration",
|
78
|
+
"spec/rspec/integration/callback_spec.rb",
|
79
|
+
"spec/rspec/integration/clr_to_clr_spec.rb",
|
80
|
+
"spec/rspec/integration/clr_to_ruby_spec.rb",
|
81
|
+
"spec/rspec/integration/indexer_spec.rb",
|
82
|
+
"spec/rspec/integration/ruby_to_ruby_spec.rb",
|
83
|
+
"spec/rspec/spec_helper.rb",
|
84
|
+
"spec/rspec/unit",
|
85
|
+
"spec/rspec/unit/core_ext_spec.rb",
|
86
|
+
"spec/rspec/unit/descriptor_spec.rb",
|
87
|
+
"spec/rspec/unit/event_spec.rb",
|
88
|
+
"spec/rspec/unit/expectation_spec.rb",
|
89
|
+
"spec/rspec/unit/interop_spec.rb",
|
90
|
+
"spec/rspec/unit/isolation_spec.rb",
|
91
|
+
"spec/rspec/unit/isolator_spec.rb",
|
92
|
+
"spec/rspec/unit/messaging_spec.rb",
|
93
|
+
"spec/rspec/unit/method_call_spec.rb",
|
94
|
+
"spec/rspec/unit/sword_spec.rb",
|
95
|
+
"spec/rspec/unit/verification_spec.rb",
|
96
|
+
"spec/spec_helper.rb"]
|
97
|
+
s.has_rdoc = true
|
98
|
+
s.homepage = "http://casualjim.github.com/caricature"
|
99
|
+
s.loaded = false
|
100
|
+
s.name = "caricature"
|
101
|
+
s.platform = "ruby"
|
102
|
+
s.rdoc_options = ["--quiet", "--title", "Caricature brings simple mocking to Ruby, DLR and CLR.", "--main", "README.rdoc", "--line-numbers", "--format", "darkfish"]
|
103
|
+
s.require_paths = ["lib"]
|
104
|
+
s.required_ruby_version = ">= 1.8.4"
|
105
|
+
s.required_rubygems_version = ">= 0"
|
106
|
+
s.rubyforge_project = "caricature"
|
107
|
+
s.rubygems_version = "1.3.5"
|
108
|
+
s.specification_version = 3
|
109
|
+
s.summary = "Caricature brings simple mocking to Ruby, DLR and CLR."
|
110
|
+
s.version = "0.7.5"
|
107
111
|
end
|
data/lib/caricature.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
+
require 'rubygems' unless defined?(Gem)
|
1
2
|
$:.unshift File.dirname(__FILE__)
|
3
|
+
require 'uuidtools'
|
2
4
|
|
3
5
|
module Caricature
|
4
6
|
#
|
@@ -8,7 +10,7 @@ module Caricature
|
|
8
10
|
#
|
9
11
|
end
|
10
12
|
|
11
|
-
require '
|
13
|
+
require 'caricature/core_ext'
|
12
14
|
require 'caricature/version'
|
13
15
|
require 'caricature/isolation'
|
14
16
|
require 'caricature/clr' if defined? IRONRUBY_VERSION
|
data/lib/caricature/bacon.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require 'caricature/bacon/integration' if defined? Bacon
|
2
|
-
|
1
|
+
require 'caricature/bacon/integration' if defined? Bacon
|
2
|
+
|
@@ -1,55 +1,75 @@
|
|
1
|
-
class Should
|
2
|
-
|
3
|
-
def have_received?(name, &b)
|
4
|
-
|
5
|
-
end
|
6
|
-
|
7
|
-
def
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
1
|
+
class Should
|
2
|
+
|
3
|
+
def have_received?(name, &b)
|
4
|
+
be(name) { |obj, *args| obj.did_receive?(name, &b).successful? }
|
5
|
+
end
|
6
|
+
|
7
|
+
def have_raised_event?(name, &b)
|
8
|
+
be(name) { |obj, *args| obj.did_raise_event?(name, &b).successful? }
|
9
|
+
end if defined?(IRONRUBY_VERSION)
|
10
|
+
|
11
|
+
def satisfy(*args, &block)
|
12
|
+
if args.size == 1 && String === args.first
|
13
|
+
description = args.shift
|
14
|
+
else
|
15
|
+
description = ""
|
16
|
+
end
|
17
|
+
r=nil
|
18
|
+
err = nil
|
19
|
+
begin
|
20
|
+
r = block.call(@object, *args)
|
21
|
+
rescue Caricature::ArgumentMatchError => e
|
22
|
+
err =e
|
23
|
+
end
|
24
|
+
if Bacon::Counter[:depth] > 0
|
25
|
+
Bacon::Counter[:requirements] += 1
|
26
|
+
raise (err.is_a?(Caricature::ArgumentMatchError) ? err : Bacon::Error.new(:failed, description)) unless @negated ^ r
|
27
|
+
r
|
28
|
+
else
|
29
|
+
@negated ? !r : !!r
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
module Caricature
|
36
|
+
|
37
|
+
# Describes a verification of a method call.
|
38
|
+
# This corresponds kind of to an assertion
|
39
|
+
class Verification
|
40
|
+
|
41
|
+
|
42
|
+
# indicate that this method verification is successful
|
43
|
+
def successful?
|
44
|
+
a = any_args? ? [:any] : @args
|
45
|
+
res = @recorder.was_called?(@method_name, @block_args, @mode, *a)
|
46
|
+
raise Caricature::ArgumentMatchError.new(:failed, self.error) unless res
|
47
|
+
res
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
end
|
52
|
+
if defined?(IRONRUBY_VERSION)
|
53
|
+
class EventVerification
|
54
|
+
|
55
|
+
# indicate that this event verification is successful
|
56
|
+
def successful?
|
57
|
+
a = any_args? ? [:any] : @args
|
58
|
+
res = @recorder.event_raised?(@event_name, @mode, *a)
|
59
|
+
raise Caricature::ArgumentMatchError.new(:failed, self.error) unless res
|
60
|
+
res
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
# class ClrInterfaceIsolator
|
66
|
+
# def
|
67
|
+
# end
|
68
|
+
end
|
69
|
+
|
70
|
+
class ArgumentMatchError < Bacon::Error;
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
data/lib/caricature/clr.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
#IronRuby.load_assembly 'Workarounds, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'
|
2
|
-
|
3
1
|
require File.dirname(__FILE__) + "/clr/descriptor"
|
4
2
|
require File.dirname(__FILE__) + "/clr/messenger"
|
5
3
|
require File.dirname(__FILE__) + "/clr/isolator"
|
6
|
-
require File.dirname(__FILE__) + "/clr/
|
4
|
+
require File.dirname(__FILE__) + "/clr/expectation"
|
5
|
+
require File.dirname(__FILE__) + "/clr/isolation"
|
6
|
+
require File.dirname(__FILE__) + "/clr/event_verification"
|
7
|
+
require File.dirname(__FILE__) + "/clr/method_call_recorder"
|
@@ -1,6 +1,6 @@
|
|
1
|
-
load_assembly 'System.Web.Routing
|
2
|
-
load_assembly 'System.Web.Mvc
|
3
|
-
load_assembly 'System.Web.Abstractions
|
1
|
+
load_assembly 'System.Web.Routing'
|
2
|
+
load_assembly 'System.Web.Mvc'
|
3
|
+
load_assembly 'System.Web.Abstractions'
|
4
4
|
|
5
5
|
include System::Web
|
6
6
|
include System::Web::Routing
|
@@ -3,41 +3,102 @@ module Caricature
|
|
3
3
|
# Contains the logic to collect members from a CLR type
|
4
4
|
module ClrMemberCollector
|
5
5
|
|
6
|
+
attr_reader :class_events, :events
|
7
|
+
|
6
8
|
private
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
9
|
+
# collects the instance members for a CLR type.
|
10
|
+
# makes sure it can handle indexers for properties etc.
|
11
|
+
def build_member_collections(context={}, instance_member=true)
|
12
|
+
|
13
|
+
build_event_collection(context, instance_member)
|
14
|
+
|
15
|
+
mem = []
|
16
|
+
mem += build_method_collection(context, instance_member)
|
17
|
+
mem += build_property_collection(context, instance_member)
|
18
|
+
mem
|
19
|
+
end
|
20
|
+
|
21
|
+
def build_property_collection(context, instance_member)
|
22
|
+
context[:properties].inject([]) do |res, pi|
|
23
|
+
prop_name = property_name_from(pi)
|
24
|
+
res << MemberDescriptor.new(prop_name, pi.property_type, instance_member)
|
25
|
+
res << MemberDescriptor.new("set_Item", nil, instance_member) if prop_name == "get_Item"
|
26
|
+
res << MemberDescriptor.new("#{prop_name}=", nil, instance_member) if pi.can_write and prop_name != "get_Item"
|
27
|
+
res
|
22
28
|
end
|
29
|
+
end
|
23
30
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
"__getitem__"
|
29
|
-
end
|
30
|
-
|
31
|
-
# the binding flags for instance members of a CLR type
|
32
|
-
def instance_flags
|
33
|
-
System::Reflection::BindingFlags.public | System::Reflection::BindingFlags.instance
|
34
|
-
end
|
35
|
-
|
36
|
-
# the binding flags for class members of a CLR type
|
37
|
-
def class_flags
|
38
|
-
System::Reflection::BindingFlags.public | System::Reflection::BindingFlags.static
|
31
|
+
def build_method_collection(context, instance_member)
|
32
|
+
context[:methods].inject([]) do |meths, mi|
|
33
|
+
meths << MemberDescriptor.new(mi.name.underscore, mi.return_type, instance_member) unless event?(mi.name, instance_member)
|
34
|
+
meths
|
39
35
|
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def build_event_collection(context, instance_member)
|
39
|
+
context[:events].inject(evts=[]) { |evc, ei| evc << ClrEventDescriptor.new(ei.name, instance_member) }
|
40
|
+
(instance_member ? @events = evts : @class_events = evts)
|
41
|
+
end
|
42
|
+
|
43
|
+
# indicates if this member is an event
|
44
|
+
def event?(name, instance_member)
|
45
|
+
((instance_member ? @events : @class_events)||[]).any? { |en| /^(add|remove)_#{en.event_name}/i =~ name }
|
46
|
+
end
|
47
|
+
|
48
|
+
# gets the property name from the +PropertyInfo+
|
49
|
+
# when the property is an indexer it will return +[]+
|
50
|
+
def property_name_from(property_info)
|
51
|
+
return property_info.name.underscore if property_info.get_index_parameters.empty?
|
52
|
+
"get_Item"
|
53
|
+
end
|
54
|
+
|
55
|
+
# the binding flags for instance members of a CLR type
|
56
|
+
def instance_flags
|
57
|
+
System::Reflection::BindingFlags.public | System::Reflection::BindingFlags.instance
|
58
|
+
end
|
59
|
+
|
60
|
+
# the binding flags for class members of a CLR type
|
61
|
+
def class_flags
|
62
|
+
System::Reflection::BindingFlags.public | System::Reflection::BindingFlags.static
|
63
|
+
end
|
64
|
+
|
65
|
+
def event_flags
|
66
|
+
non_public_flag | instance_flags
|
67
|
+
end
|
68
|
+
|
69
|
+
def class_event_flags
|
70
|
+
non_public_flag | class_flags
|
71
|
+
end
|
72
|
+
|
73
|
+
def non_public_flag
|
74
|
+
System::Reflection::BindingFlags.non_public
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
class ClrEventDescriptor
|
80
|
+
|
81
|
+
attr_reader :event_name
|
40
82
|
|
83
|
+
def initialize(event_name, instance_member=true)
|
84
|
+
@event_name, @instance_member = event_name, instance_member
|
85
|
+
end
|
86
|
+
|
87
|
+
def instance_member?
|
88
|
+
@instance_member
|
89
|
+
end
|
90
|
+
|
91
|
+
def add_method_name
|
92
|
+
"add_#{event_name}"
|
93
|
+
end
|
94
|
+
|
95
|
+
def remove_method_name
|
96
|
+
"remove_#{event_name}"
|
97
|
+
end
|
98
|
+
|
99
|
+
def to_s
|
100
|
+
"<#{self.class}:#{object_id} @event_name=\"#{event_name}\">"
|
101
|
+
end
|
41
102
|
end
|
42
103
|
|
43
104
|
# describes clr interfaces.
|
@@ -51,10 +112,12 @@ module Caricature
|
|
51
112
|
def initialize_instance_members_for(klass)
|
52
113
|
clr_type = klass.to_clr_type
|
53
114
|
|
54
|
-
|
55
|
-
|
115
|
+
context = {}
|
116
|
+
context[:properties] = clr_type.collect_interface_properties
|
117
|
+
context[:methods] = clr_type.collect_interface_methods
|
118
|
+
context[:events] = clr_type.collect_interface_events
|
56
119
|
|
57
|
-
@instance_members =
|
120
|
+
@instance_members = build_member_collections context
|
58
121
|
end
|
59
122
|
|
60
123
|
# this method is empty because an interface can't have static members
|
@@ -72,20 +135,24 @@ module Caricature
|
|
72
135
|
def initialize_instance_members_for(klass)
|
73
136
|
clr_type = klass.to_clr_type
|
74
137
|
|
75
|
-
|
76
|
-
|
138
|
+
context = {}
|
139
|
+
context[:methods] = clr_type.get_methods(instance_flags)
|
140
|
+
context[:properties] = clr_type.get_properties(instance_flags)
|
141
|
+
context[:events] = clr_type.get_events(event_flags)
|
77
142
|
|
78
|
-
@instance_members =
|
143
|
+
@instance_members = build_member_collections context
|
79
144
|
end
|
80
145
|
|
81
146
|
# collects all the static members of the provided CLR class type
|
82
147
|
def initialize_class_members_for(klass)
|
83
148
|
clr_type = klass.to_clr_type
|
84
149
|
|
85
|
-
|
86
|
-
|
150
|
+
context = {}
|
151
|
+
context[:methods] = clr_type.get_methods(class_flags)
|
152
|
+
context[:properties] = clr_type.get_properties(class_flags)
|
153
|
+
context[:events] = clr_type.get_events(class_event_flags)
|
87
154
|
|
88
|
-
@class_members =
|
155
|
+
@class_members = build_member_collections context, false
|
89
156
|
end
|
90
157
|
|
91
158
|
end
|