Class: ExtDirect::Api
- Inherits:
-
Object
- Object
- ExtDirect::Api
- Defined in:
- lib/ext_direct/api.rb
Overview
Instance Attribute Summary collapse
-
#exposed_api ⇒ Object
readonly
Returns the value of attribute exposed_api.
Class Method Summary collapse
-
.expose(class_to_expose, options = {}) ⇒ Hash
Expose a class.
-
.expose_all(class_dir) ⇒ Object
Expose all classes in a directory(conviniance method).
-
.to_json ⇒ String
Return all exposed classes as a JSON String.
-
.to_raw ⇒ Hash
Return a Hash of all exposed classes.
Instance Attribute Details
#exposed_api ⇒ Object (readonly)
Returns the value of attribute exposed_api.
7 8 9 |
# File 'lib/ext_direct/api.rb', line 7 def exposed_api @exposed_api end |
Class Method Details
.expose(class_to_expose, options = {}) ⇒ Hash
Expose a class
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ext_direct/api.rb', line 15 def self.expose(class_to_expose, = {}) @exposed_api = {} if @exposed_api.nil? methods = [] if .include?(:only) raw_methods = [:only] || [] else raw_methods = class_to_expose.instance_methods(false) - ([:except] || []) end raw_methods.uniq! raw_methods.each do |m| name = m len = class_to_expose.instance_method(m).parameters.size methods << {:name => name, :len => len} end @exposed_api.store(class_to_expose.name, methods) end |
.expose_all(class_dir) ⇒ Object
Expose all classes in a directory(conviniance method)
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ext_direct/api.rb', line 40 def self.expose_all(class_dir) @exposed_api = {} Dir.glob("#{class_dir}/**/*.rb").each do |r| rr = r.split("#{class_dir}/")[1].gsub('.rb','') puts "#{class_dir}/#{rr}" require "#{class_dir}/#{rr}" klass = self.class.const_get(rr.split('_').map{|c| c.capitalize}.join('')) self.expose klass end end |
.to_json ⇒ String
Return all exposed classes as a JSON String
57 58 59 60 |
# File 'lib/ext_direct/api.rb', line 57 def self.to_json api = self.to_raw "REMOTING_API = #{api.to_json};" end |
.to_raw ⇒ Hash
Return a Hash of all exposed classes
66 67 68 69 70 |
# File 'lib/ext_direct/api.rb', line 66 def self.to_raw api = {:url => '/router', :type => 'remoting', :actions => @exposed_api} end |