Skip to content
This repository was archived by the owner on Oct 19, 2018. It is now read-only.

Commit 3f71ceb

Browse files
committed
added missing files
1 parent 6bf958f commit 3f71ceb

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

hyperloop-config-0.8.0.gem

7 KB
Binary file not shown.

lib/hyperloop-config.rb

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
module Hyperloop
2+
# configuration utility
3+
class << self
4+
5+
def initialized_blocks
6+
@initialized_blocks ||= []
7+
end
8+
9+
def reset_blocks
10+
@reset_blocks ||= []
11+
end
12+
13+
def configuration
14+
reset_blocks.each(&:call)
15+
yield self
16+
initialized_blocks.each(&:call)
17+
end
18+
19+
def define_setting(name, default = nil, &block)
20+
class_variable_set("@@#{name}", default)
21+
22+
define_class_method "#{name}=" do |value|
23+
class_variable_set("@@#{name}", value)
24+
block.call value if block
25+
value
26+
end
27+
28+
define_class_method name do
29+
class_variable_get("@@#{name}")
30+
end
31+
end
32+
33+
def on_config_reset &block
34+
reset_blocks << block
35+
end
36+
37+
def on_config_initialized &block
38+
initialized_blocks << block
39+
end
40+
41+
private
42+
43+
def define_class_method(name, &block)
44+
(class << self; self; end).instance_eval do
45+
define_method name, &block
46+
end
47+
end
48+
end
49+
end

0 commit comments

Comments
 (0)