Class: PublicAPI

Inherits:
Object
  • Object
show all
Defined in:
lib/appswarm/public_api.rb

Instance Method Summary collapse

Constructor Details

#initialize(target) ⇒ PublicAPI

Returns a new instance of PublicAPI.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/appswarm/public_api.rb', line 5

def initialize(target)
  @@api||={}
  @target=target
  this=self
  @target.class_eval{
    @@_api=this
    def self.api(*s)
      @@_api.addAPI(self,*s)
    end
    def api(*s)
      @@_api.api(self,*s)
    end
  }
end

Instance Method Details

#addAPI(this, *s) ⇒ Object



19
20
21
22
# File 'lib/appswarm/public_api.rb', line 19

def addAPI(this,*s)
  @@api[this]||=[]
  @@api[this]+=s
end

#api(object, *s) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/appswarm/public_api.rb', line 23

def api(object,*s)
  if @@api[object.class].member?(s[0])
    object.send(*s)
  else
    raise AccessViolationException.new      
  end
end