dynaload 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,81 @@
1
+ module Dynaload
2
+ VERSION = '0.2.0'
3
+
4
+ class ExportError < ::StandardError; end
5
+
6
+ class Exported < ::Hash
7
+ THINGS = %w( classes modules objects )
8
+ def initialize(*a, &b)
9
+ super
10
+ THINGS.each{|thing| self[thing] = []}
11
+ end
12
+ def method_missing(m,*a,&b)
13
+ self[m] || self["#{ m }"] || super
14
+ end
15
+ def empty?
16
+ THINGS.map{|thing| self[thing].empty?}.all?
17
+ end
18
+ def clear!
19
+ THINGS.each{|thing| self[thing].clear}
20
+ self
21
+ end
22
+ def
23
+ case thing
24
+ when Class
25
+ dyna_exported.classes << [thing, attributes]
26
+ when Module
27
+ dyna_exported.modules << [thing, attributes]
28
+ else
29
+ dyna_exported.objects << [thing, attributes]
30
+ end
31
+ end
32
+
33
+ module Dynaloadable
34
+ module ClassMethods
35
+ def dyna_exported
36
+ ::Dynaload::exported ||= ::Dynaload::Exported::new
37
+ end
38
+ def dyna_export *args
39
+ things, attribute_hashes = args.partition{|arg| not Hash === arg}
40
+ raise ArgumentError, "nothing given to dyna_export!" if things.empty?
41
+ attributes = attribute_hashes.inject({}){|h,ah| h.update ah}
42
+ things.each do |thing|
43
+ case thing
44
+ when Class
45
+ dyna_exported.classes << [thing, attributes]
46
+ when Module
47
+ dyna_exported.modules << [thing, attributes]
48
+ else
49
+ dyna_exported.objects << [thing, attributes]
50
+ end
51
+ end
52
+ dyna_exported.classes.uniq!
53
+ dyna_exported.modules.uniq!
54
+ dyna_exported.objects.uniq!
55
+ dyna_exported
56
+ end
57
+ alias_method "export", "dyna_export"
58
+ alias_method "exported", "dyna_exported"
59
+ end
60
+ module InstanceMethods; end
61
+ extend ClassMethods
62
+ def self::included other
63
+ other.extend ClassMethods
64
+ other.module_eval{ include InstanceMethods }
65
+ end
66
+ end
67
+
68
+ class Dynaloader
69
+ def dynaload path
70
+ ::Kernel::load path, true
71
+ raise ExportError, "no dynamic exports from <#{ path }>!" if Dynaload::exported.empty?
72
+ Dynaload::exported
73
+ end
74
+ end
75
+
76
+ include Dynaloadable
77
+
78
+ def self::dynaload(*a, &b)
79
+ (@dynaloader ||= Dynaloader::new).dynaload(*a, &b)
80
+ end
81
+ end
@@ -1,110 +1,67 @@
1
1
  module Dynaload
2
- #--{{{
3
- VERSION = '0.1.1'
2
+ VERSION = '0.2.0'
3
+
4
+ require "sync"
5
+
6
+ extend Sync_m
7
+
4
8
  class ExportError < ::StandardError; end
9
+
5
10
  class Exported < ::Hash
6
- #--{{{
7
- def initialize(*a, &b)
8
- #--{{{
11
+ THINGS = %w( classes modules objects )
12
+ def initialize *a, &b
9
13
  super
10
- self['classes'] = []
11
- self['modules'] = []
12
- self['objects'] = []
13
- #--}}}
14
+ THINGS.each{|thing| self[thing] = []}
14
15
  end
15
- def method_missing(m,*a,&b)
16
- #--{{{
17
- self[m] || self["#{ m }"] || super
18
- #--}}}
16
+ def method_missing m, *a, &b
17
+ self["#{ m }"] || super
19
18
  end
20
- #--}}}
21
- end
22
- module DynaloadableMethods
23
- #--{{{
24
- def dyna_exported
25
- #--{{{
26
- Dynaload::exported ||= Exported::new
27
- #--}}}
19
+ def empty?
20
+ THINGS.map{|thing| self[thing].empty?}.all?
28
21
  end
29
- def dyna_export(*args)
30
- #--{{{
31
- things, attribute_hashes = args.partition{|arg| not Hash === arg}
32
- raise ArgumentError, "nothing given to dyna_export!" if things.empty?
33
- attributes = attribute_hashes.inject({}){|h,ah| h.update ah}
34
- things.each do |thing|
35
- case thing
36
- when Class
37
- dyna_exported.classes << [thing, attributes]
38
- when Module
39
- dyna_exported.modules << [thing, attributes]
40
- else
41
- dyna_exported.objects << [thing, attributes]
42
- end
43
- end
44
- dyna_exported.classes.uniq!
45
- dyna_exported.modules.uniq!
46
- dyna_exported.objects.uniq!
47
- dyna_exported
48
- #--}}}
22
+ def clear!
23
+ THINGS.each{|thing| self[thing].clear}
24
+ self
49
25
  end
50
- alias export dyna_export
51
- alias exported dyna_exported
52
- #--}}}
53
- end
54
- module Dynaloadable
55
- #--{{{
56
- include DynaloadableMethods
57
- class << self
58
- #--{{{
59
- include DynaloadableMethods
60
- def append_features klass
61
- #--{{{
62
- klass.extend DynaloadableMethods
63
- super
64
- #--}}}
26
+ def export thing, attributes
27
+ case thing
28
+ when Class
29
+ (self['classes'] << [thing, attributes]).uniq!
30
+ when Module
31
+ (self['modules'] << [thing, attributes]).uniq!
32
+ else
33
+ (self['objects'] << [thing, attributes]).uniq!
65
34
  end
66
- #--}}}
35
+ self
67
36
  end
68
- #--}}}
69
- end
70
- class Dynaloader
71
- #--{{{
72
- def dynaload path, opts = {}
73
- #--{{{
74
- wrap = true
75
- wrap = opts[:wrap] if opts.has_key? :wrap
76
- wrap = opts['wrap'] if opts.has_key? 'wrap'
77
- Dynaload::exported = nil
78
- Kernel::load path, wrap
79
- raise ExportError, "no dynamic exports from <#{ path }>!" unless Exported === Dynaload::exported
80
- Dynaload::exported
81
- #--}}}
37
+ def dup
38
+ THINGS.inject({}){|h,t| h[t] = self[t].dup}
82
39
  end
83
- alias dyna_load dynaload
84
- alias load dynaload
85
- #--}}}
86
40
  end
41
+
87
42
  class << self
88
- #--{{{
89
- def dynaload(*a, &b)
90
- #--{{{
91
- (@dynaloader ||= Dynaloader::new).dynaload(*a, &b)
92
- #--}}}
93
- end
94
- alias dyna_load dynaload
95
- alias load dynaload
96
43
  def exported
97
- #--{{{
98
- @exported ||= Exported::new
99
- #--}}}
44
+ synchronize{ @exported ||= Exported::new }
45
+ end
46
+
47
+ def export thing, attributes = {}
48
+ synchronize{ exported.export thing, attributes }
100
49
  end
101
- def exported= e
102
- #--{{{
103
- @exported = e
104
- #--}}}
50
+
51
+ def dynaload path, opts = {"wrap" => true}
52
+ ret = nil
53
+ synchronize do
54
+ begin
55
+ @exported = Exported::new
56
+ ::Kernel::load(path, opts["wrap"] || opts[:wrap])
57
+ raise ExportError, "no dynamic exports from <#{ path }>!" if
58
+ @exported.nil? or @exported.empty?
59
+ ret = @exported
60
+ ensure
61
+ @exported = nil
62
+ end
63
+ end
64
+ ret
105
65
  end
106
- #--}}}
107
66
  end
108
- include Dynaloadable
109
- #--}}}
110
67
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: dynaload
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.1
7
- date: 2005-12-09 00:00:00.000000 -07:00
6
+ version: 0.2.0
7
+ date: 2005-12-12 00:00:00 -07:00
8
8
  summary: dynaload
9
9
  require_paths:
10
10
  - lib
@@ -29,8 +29,8 @@ cert_chain:
29
29
  authors:
30
30
  - Ara T. Howard
31
31
  files:
32
+ - lib/dynaload-0.2.0.rb
32
33
  - lib/dynaload.rb
33
- - lib/dynaload-0.1.1.rb
34
34
  test_files: []
35
35
  rdoc_options: []
36
36
  extra_rdoc_files: []
@@ -1,110 +0,0 @@
1
- module Dynaload
2
- #--{{{
3
- VERSION = '0.1.1'
4
- class ExportError < ::StandardError; end
5
- class Exported < ::Hash
6
- #--{{{
7
- def initialize(*a, &b)
8
- #--{{{
9
- super
10
- self['classes'] = []
11
- self['modules'] = []
12
- self['objects'] = []
13
- #--}}}
14
- end
15
- def method_missing(m,*a,&b)
16
- #--{{{
17
- self[m] || self["#{ m }"] || super
18
- #--}}}
19
- end
20
- #--}}}
21
- end
22
- module DynaloadableMethods
23
- #--{{{
24
- def dyna_exported
25
- #--{{{
26
- Dynaload::exported ||= Exported::new
27
- #--}}}
28
- end
29
- def dyna_export(*args)
30
- #--{{{
31
- things, attribute_hashes = args.partition{|arg| not Hash === arg}
32
- raise ArgumentError, "nothing given to dyna_export!" if things.empty?
33
- attributes = attribute_hashes.inject({}){|h,ah| h.update ah}
34
- things.each do |thing|
35
- case thing
36
- when Class
37
- dyna_exported.classes << [thing, attributes]
38
- when Module
39
- dyna_exported.modules << [thing, attributes]
40
- else
41
- dyna_exported.objects << [thing, attributes]
42
- end
43
- end
44
- dyna_exported.classes.uniq!
45
- dyna_exported.modules.uniq!
46
- dyna_exported.objects.uniq!
47
- dyna_exported
48
- #--}}}
49
- end
50
- alias export dyna_export
51
- alias exported dyna_exported
52
- #--}}}
53
- end
54
- module Dynaloadable
55
- #--{{{
56
- include DynaloadableMethods
57
- class << self
58
- #--{{{
59
- include DynaloadableMethods
60
- def append_features klass
61
- #--{{{
62
- klass.extend DynaloadableMethods
63
- super
64
- #--}}}
65
- end
66
- #--}}}
67
- end
68
- #--}}}
69
- end
70
- class Dynaloader
71
- #--{{{
72
- def dynaload path, opts = {}
73
- #--{{{
74
- wrap = true
75
- wrap = opts[:wrap] if opts.has_key? :wrap
76
- wrap = opts['wrap'] if opts.has_key? 'wrap'
77
- Dynaload::exported = nil
78
- Kernel::load path, wrap
79
- raise ExportError, "no dynamic exports from <#{ path }>!" unless Exported === Dynaload::exported
80
- Dynaload::exported
81
- #--}}}
82
- end
83
- alias dyna_load dynaload
84
- alias load dynaload
85
- #--}}}
86
- end
87
- class << self
88
- #--{{{
89
- def dynaload(*a, &b)
90
- #--{{{
91
- (@dynaloader ||= Dynaloader::new).dynaload(*a, &b)
92
- #--}}}
93
- end
94
- alias dyna_load dynaload
95
- alias load dynaload
96
- def exported
97
- #--{{{
98
- @exported ||= Exported::new
99
- #--}}}
100
- end
101
- def exported= e
102
- #--{{{
103
- @exported = e
104
- #--}}}
105
- end
106
- #--}}}
107
- end
108
- include Dynaloadable
109
- #--}}}
110
- end