Permalink
Browse files

server/base: ported most functionality

  • Loading branch information...
1 parent 6421d34 commit 51f0928987821ebd1be52ea7695d02f2deb45a09 @meh committed Jul 17, 2011
View
@@ -19,4 +19,5 @@ Gem::Specification.new {|s|
s.add_dependency('actionpool')
s.add_dependency('memoized')
s.add_dependency('refining')
+ s.add_dependency('refr')
}
@@ -45,11 +45,13 @@ def alias? (name)
def call (*args, &block)
@callbacks.each {|callback|
- if @thing && @string && args.empty?
- callback.call(@thing, @string)
- else
- callback.call(*args, &block)
- end
+ begin
+ if @thing && @string && args.empty?
+ callback.call(Reference[@thing], Reference[@string])
+ else
+ callback.call(*args.map {|arg| Reference[arg]}, &block)
+ end
+ rescue LocalJumpError; end
}
end
end
@@ -23,6 +23,7 @@
require 'yaml'
require 'memoized'
require 'refining'
+require 'refr'
class Module
def scopes_for (name)
@@ -104,25 +105,6 @@ def lock_with_hack
alias lock lock_with_hack
end
-class Reference
- def initialize (name, vars)
- @getter = eval "lambda { #{name} }", vars
- @setter = eval "lambda { |v| #{name} = v }", vars
- end
-
- def value
- @getter.call
- end
-
- def value= (val)
- @setter.call(val)
- end
-end
-
-def ref (&block)
- Reference.new(block.call, block.binding)
-end
-
class String
def interpolate (on=nil)
begin
@@ -29,8 +29,16 @@ def self.[] (name, value)
end
def self.define (&block)
- Class.new(Modes) {
- @@definitions = Definitions.new(&block)
+ Class.new(Modes).tap {|klass|
+ klass.define_singleton_method :definitions do
+ @definitions ||= Definitions.new(&block)
+ end
+
+ klass.instance_eval {
+ define_method :definitions do
+ klass.definitions
+ end
+ }
}
end
@@ -68,7 +76,7 @@ def [] (name)
return @modes[name] if @modes[name]
- definition = @@definitions.find(name)
+ definition = definitions.find(name)
@modes[definition.name] = @modes[definition.code] = Mode.new(definition)
end
@@ -102,7 +110,7 @@ def - (data)
end
def supports? (name)
- !!@@definitions.find(name)
+ !!definitions.find(name)
end
def can
@@ -144,7 +152,7 @@ def to_s
end
def inspect
- @@definitions.to_s
+ definitions.to_s
end
end
@@ -31,7 +31,7 @@ def initialize (parent, *args)
end
def initialize (&block)
- self.instance_eval(&block)
+ self.instance_exec(self, &block)
end
def method_missing (name, code, options={})
@@ -108,6 +108,10 @@ def ip
def name
@options[:server][:name] || 'failirc'
end
+
+ def to_s
+ host
+ end
end
end
Oops, something went wrong.

0 comments on commit 51f0928

Please sign in to comment.