dynaload 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/dynaload-0.1.0.rb +110 -0
  2. data/lib/dynaload.rb +110 -0
  3. metadata +40 -0
@@ -0,0 +1,110 @@
1
+ module Dynaload
2
+ #--{{{
3
+ VERSION = '0.1.0'
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
+ dyna_exported.classes.uniq!
39
+ when Module
40
+ dyna_exported.modules << [thing, attributes]
41
+ dyna_exported.modules.uniq!
42
+ else
43
+ dyna_exported.objects << [thing, attributes]
44
+ dyna_exported.objects.uniq!
45
+ end
46
+ end
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
@@ -0,0 +1,110 @@
1
+ module Dynaload
2
+ #--{{{
3
+ VERSION = '0.1.0'
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
+ dyna_exported.classes.uniq!
39
+ when Module
40
+ dyna_exported.modules << [thing, attributes]
41
+ dyna_exported.modules.uniq!
42
+ else
43
+ dyna_exported.objects << [thing, attributes]
44
+ dyna_exported.objects.uniq!
45
+ end
46
+ end
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
metadata ADDED
@@ -0,0 +1,40 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.8.11
3
+ specification_version: 1
4
+ name: dynaload
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.1.0
7
+ date: 2005-11-19 00:00:00.000000 -07:00
8
+ summary: dynaload
9
+ require_paths:
10
+ - lib
11
+ email: ara.t.howard@noaa.gov
12
+ homepage: http://codeforpeople.com/lib/ruby/dynaload/
13
+ rubyforge_project:
14
+ description:
15
+ autorequire: dynaload
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: false
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ -
22
+ - ">"
23
+ - !ruby/object:Gem::Version
24
+ version: 0.0.0
25
+ version:
26
+ platform: ruby
27
+ signing_key:
28
+ cert_chain:
29
+ authors:
30
+ - Ara T. Howard
31
+ files:
32
+ - lib/dynaload.rb
33
+ - lib/dynaload-0.1.0.rb
34
+ test_files: []
35
+ rdoc_options: []
36
+ extra_rdoc_files: []
37
+ executables: []
38
+ extensions: []
39
+ requirements: []
40
+ dependencies: []