class Aries::Generator
Public Class Methods
generate(schema_path, options)
click to toggle source
# File lib/aries/generator.rb, line 5 def self.generate schema_path, options new(schema_path, options).exec end
new(schema_path, options ={})
click to toggle source
@param file_path
[String] json schema file path
# File lib/aries/generator.rb, line 12 def initialize schema_path, options ={} @schema_path = schema_path @output_path = options[:output_path] || Dir.pwd @class_name = options[:class_name] || "AriesApi" @language = options[:language] || "swift" @base_url = options[:base_url] end
Public Instance Methods
base_url()
click to toggle source
@return [String]
# File lib/aries/generator.rb, line 57 def base_url @base_url || schema.base_url end
class_name()
click to toggle source
@return [String]
# File lib/aries/generator.rb, line 34 def class_name @class_name.camelcase end
exec()
click to toggle source
@return [TrueClass, FalseClass]
# File lib/aries/generator.rb, line 86 def exec return puts "File already exists" if File.exist?(file_path) File.write file_path, template.result(binding) true end
extension()
click to toggle source
@return [String]
# File lib/aries/generator.rb, line 44 def extension case @language when "swift" then "swift" when "java" then "java" end end
file_name()
click to toggle source
@return [String]
# File lib/aries/generator.rb, line 52 def file_name class_name + "." + extension end
file_path()
click to toggle source
@return [String]
# File lib/aries/generator.rb, line 72 def file_path output_path + "/" + file_name end
original_schema()
click to toggle source
@return [Aries::Schema]
# File lib/aries/generator.rb, line 29 def original_schema Schema.new JSON.parse(File.read(@schema_path)) end
output_path()
click to toggle source
@return [String]
# File lib/aries/generator.rb, line 39 def output_path @output_path end
resources()
click to toggle source
@return [Array<Aries::Presenters::ResourceSwift>]
# File lib/aries/generator.rb, line 62 def resources schema.resources end
schema()
click to toggle source
@return [Aries::Presenters::SchemaSwift]
# File lib/aries/generator.rb, line 21 def schema case @language when "swift" Aries::Presenters::SchemaSwift.new original_schema end end
template()
click to toggle source
@return [ERB]
# File lib/aries/generator.rb, line 77 def template Erubis::Eruby.new File.read(template_path), trim: true end
template_path()
click to toggle source
@return [String]
# File lib/aries/generator.rb, line 67 def template_path File.expand_path("../templates/client.#{@language}.erb", __FILE__) end
timestamp()
click to toggle source
# File lib/aries/generator.rb, line 81 def timestamp Time.now.strftime('%Y/%m/%d') end