requirium 0.0.3 → 0.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dea42646908a945fb4fa22ca909c6fe0c51bb28c
4
- data.tar.gz: 29f6c119d45605fce3f7505abc1b07ad122b4c92
3
+ metadata.gz: eaeb02dd4c979c7c0d610fca588f890f22bbb40d
4
+ data.tar.gz: d7a7acb203652154316a9f79ad91a380d32493a0
5
5
  SHA512:
6
- metadata.gz: 24549e4c742ece2fc12efe9dc5d10f890074c92c6a1896a9fb2f3845bd0e3c2fede558d9e1dd2dc0c4a7dbe5754e6118d864d460eadc7ad85ce6e74d043e3f30
7
- data.tar.gz: 49c6ad6a458f7eb484e58f53c4c6c35a572458c6a21c1e71536e4c9242b4d1841365a86e407d251ab37dd87d5e602056a8e592aab37db226962a5d68b9c96c8f
6
+ metadata.gz: ff0e9ba46cd44ca282958b86e450d33d3b666c0a7307e96a5ede7290ce8299ca57a6834e452dd051fc142f063a3a45bf01c2d3d5458fdd323b952cdde1dbc7cf
7
+ data.tar.gz: 2f5b961015812a391151513c79ff687c300f4093da11a34ac79fcd18839c27e3dbe62b005570e58e5ce6b39d9c142f24a5292cf6e82d6ece7fcb9050d2881447
data/lib/const_info.rb CHANGED
@@ -1,12 +1,18 @@
1
1
  class Requirium::ConstInfo
2
- attr_accessor :mod, :sym
2
+ attr_accessor :mod, :sym, :error, :value
3
3
 
4
4
  def initialize(mod, sym)
5
5
  @mod, @sym, @cond, @mutex = mod, sym, ConditionVariable.new, Mutex.new
6
6
  end
7
7
 
8
+ def has_value?
9
+ !!(defined? @value)
10
+ end
11
+
8
12
  def internal_load
9
- mod.send(:internal_load, sym)
13
+ has, value = mod.send(:internal_load, sym)
14
+ @value = value if has
15
+ nil
10
16
  end
11
17
 
12
18
  def ready!
data/lib/requirium.rb CHANGED
@@ -37,9 +37,9 @@ module Requirium
37
37
  begin
38
38
  info.internal_load
39
39
  rescue ScriptError => e
40
- $stderr.puts e
40
+ info.error = e
41
41
  rescue => e
42
- $stderr.puts e
42
+ info.error = e
43
43
  ensure
44
44
  info.ready!
45
45
  end
@@ -71,11 +71,16 @@ module Requirium
71
71
  #end
72
72
 
73
73
  def const_missing(sym)
74
- return internal_load(sym) if Thread.current == Requirium.loader_thread
74
+ if Thread.current == Requirium.loader_thread
75
+ # this avoids deadlocks. it uses the current loading to load the remaining dependencies
76
+ has, value = internal_load(sym)
77
+ return has ? value : super
78
+ end
75
79
 
76
80
  Requirium.queue.push(info = ConstInfo.new(self, sym))
77
81
  info.wait_ready
78
- const_defined?(sym) ? const_get(sym) : super
82
+ raise info.error if info.error
83
+ info.has_value? ? info.value : super
79
84
  end
80
85
 
81
86
  private
@@ -87,18 +92,12 @@ module Requirium
87
92
  end
88
93
 
89
94
  def internal_load(sym)
90
- return const_get(sym) if const_defined?(sym)
91
- str_sym = sym.to_s
92
- loader = load_list { |l| l[str_sym] }
93
-
94
- return home.const_missing(sym) unless loader # go to parent
95
-
96
- loader.call(self)
97
-
98
- if const_defined?(sym)
99
- load_list { |l| l.delete(sym.to_s) }
100
- const_get(sym)
95
+ lookup_list.find do |klass|
96
+ klass.send(:try_load, sym) if klass.singleton_class.include?(Requirium)
97
+ return [true, klass.const_get(sym)] if klass.const_defined?(sym)
101
98
  end
99
+
100
+ [false, nil]
102
101
  end
103
102
 
104
103
  def load_list
@@ -107,6 +106,15 @@ module Requirium
107
106
  @mutex.synchronize { yield(@load_list) }
108
107
  end
109
108
 
109
+ def try_load(sym)
110
+ str_sym = sym.to_s
111
+ loader = load_list { |l| l[str_sym] }
112
+ return unless loader
113
+ loader.call(self)
114
+ load_list { |l| l.delete(sym.to_s) }
115
+ nil
116
+ end
117
+
110
118
  def with_args(args)
111
119
  if args.length == 1 && args.first.is_a?(Hash)
112
120
  args.first.each do |sym, paths|
@@ -119,4 +127,12 @@ module Requirium
119
127
 
120
128
  nil
121
129
  end
130
+
131
+ def lookup_list
132
+ list = name.split('::').reduce([Object]) { |a, n| a << a.last.const_get(n) }.reverse!
133
+ list.push(*ancestors)
134
+ list.uniq!
135
+ list
136
+ end
137
+
122
138
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Requirium
2
- VERSION = '0.0.3'.freeze
2
+ VERSION = '0.0.5'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: requirium
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - SilverPhoenix99
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-13 00:00:00.000000000 Z
11
+ date: 2014-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: facets