Module: RPCoder

Defined in:
lib/rpcoder.rb,
lib/rpcoder/type.rb,
lib/rpcoder/param.rb,
lib/rpcoder/function.rb

Defined Under Namespace

Classes: Function, Param, Type

Class Method Summary collapse

Class Method Details

.api_class_nameObject



21
22
23
# File 'lib/rpcoder.rb', line 21

def api_class_name
  @api_class_name
end

.api_class_name=(name) ⇒ Object



17
18
19
# File 'lib/rpcoder.rb', line 17

def api_class_name=(name)
  @api_class_name = name
end

.clearObject



97
98
99
100
# File 'lib/rpcoder.rb', line 97

def clear
  functions.clear
  types.clear
end

.dir_to_export_classes(dir) ⇒ Object



93
94
95
# File 'lib/rpcoder.rb', line 93

def dir_to_export_classes(dir)
  File.join(dir, *name_space.split('.'))
end

.export(dir) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/rpcoder.rb', line 49

def export(dir)
  class_dir = dir_to_export_classes(dir)
  FileUtils.mkdir_p(class_dir)

  [
    {:path => File.join(class_dir, api_class_name.split('.').last + "Interface.as"), :content => render_functions_interface},
    {:path => File.join(class_dir, api_class_name.split('.').last + ".as"), :content => render_functions},
    {:path => File.join(class_dir, api_class_name.split('.').last + "Dummy.as"), :content => render_functions_dummy},
  ].each do |hash|
    puts "API: #{hash[:path]}"
    File.open(hash[:path], "w") { |file| file << hash[:content] }
  end
  types.each { |type| export_type(type, File.join(class_dir, "#{type.name}.as")) }
end

.export_type(type, path) ⇒ Object



76
77
78
79
# File 'lib/rpcoder.rb', line 76

def export_type(type, path)
  puts "Type: #{path}"
  File.open(path, "w") { |file| file << render_type(type) }
end

.function(name) {|func| ... } ⇒ Object

Yields:

  • (func)


41
42
43
44
45
46
47
# File 'lib/rpcoder.rb', line 41

def function(name)
  func = Function.new
  func.name = name
  yield func
  functions << func
  func
end

.functionsObject



37
38
39
# File 'lib/rpcoder.rb', line 37

def functions
  @functions ||= []
end

.name_spaceObject



13
14
15
# File 'lib/rpcoder.rb', line 13

def name_space
  @name_space
end

.name_space=(name_space) ⇒ Object



9
10
11
# File 'lib/rpcoder.rb', line 9

def name_space=(name_space)
  @name_space = name_space
end

.render_erb(template, _binding) ⇒ Object



85
86
87
# File 'lib/rpcoder.rb', line 85

def render_erb(template, _binding)
  ERB.new(File.read(template_path(template)), nil, '-').result(_binding)
end

.render_functionsObject



68
69
70
# File 'lib/rpcoder.rb', line 68

def render_functions
  render_erb('API.erb', binding)
end

.render_functions_dummyObject



72
73
74
# File 'lib/rpcoder.rb', line 72

def render_functions_dummy
  render_erb('APIDummy.erb', binding)
end

.render_functions_interfaceObject



64
65
66
# File 'lib/rpcoder.rb', line 64

def render_functions_interface
  render_erb('APIInterface.erb', binding)
end

.render_type(type) ⇒ Object



81
82
83
# File 'lib/rpcoder.rb', line 81

def render_type(type)
  render_erb('Type.erb', binding)
end

.template_path(name) ⇒ Object



89
90
91
# File 'lib/rpcoder.rb', line 89

def template_path(name)
  File.join File.dirname(__FILE__), 'templates', name
end

.type(name) {|type| ... } ⇒ Object

Yields:



29
30
31
32
33
34
35
# File 'lib/rpcoder.rb', line 29

def type(name)
  type = Type.new
  type.name = name
  yield type
  types << type
  type
end

.typesObject



25
26
27
# File 'lib/rpcoder.rb', line 25

def types
  @types ||= []
end