Class: Rack::BertRpc::Mod
- Inherits:
-
Object
- Object
- Rack::BertRpc::Mod
- Defined in:
- lib/rack/bert_rpc/mod.rb
Instance Attribute Summary collapse
-
#funs ⇒ Object
readonly
Returns the value of attribute funs.
-
#loaded ⇒ Object
writeonly
Sets the attribute loaded.
-
#source_module ⇒ Object
readonly
Returns the value of attribute source_module.
Instance Method Summary collapse
- #call_fun(fun, args) ⇒ Object
-
#initialize(source_module) ⇒ Mod
constructor
A new instance of Mod.
- #load_module ⇒ Object
- #loaded? ⇒ Boolean
Constructor Details
#initialize(source_module) ⇒ Mod
Returns a new instance of Mod.
7 8 9 10 11 |
# File 'lib/rack/bert_rpc/mod.rb', line 7 def initialize(source_module) @source_module = source_module @loaded = false @funs = {} end |
Instance Attribute Details
#funs ⇒ Object (readonly)
Returns the value of attribute funs.
4 5 6 |
# File 'lib/rack/bert_rpc/mod.rb', line 4 def funs @funs end |
#loaded=(value) ⇒ Object (writeonly)
Sets the attribute loaded
5 6 7 |
# File 'lib/rack/bert_rpc/mod.rb', line 5 def loaded=(value) @loaded = value end |
#source_module ⇒ Object (readonly)
Returns the value of attribute source_module.
4 5 6 |
# File 'lib/rack/bert_rpc/mod.rb', line 4 def source_module @source_module end |
Instance Method Details
#call_fun(fun, args) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rack/bert_rpc/mod.rb', line 13 def call_fun(fun, args) unless loaded? load_module end if funs[fun].nil? raise(ServerError.new("No such function " + "'#{source_module.name}##{fun}'")) end funs[fun].call(*args) end |
#load_module ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/rack/bert_rpc/mod.rb', line 30 def load_module @context = Object.new @context.extend source_module source_module.public_instance_methods.each do |meth| funs[meth.to_sym] = @context.method(meth) end self.loaded = true end |
#loaded? ⇒ Boolean
26 27 28 |
# File 'lib/rack/bert_rpc/mod.rb', line 26 def loaded? @loaded end |