Class: Aries::Generator
- Inherits:
-
Object
- Object
- Aries::Generator
- Defined in:
- lib/aries/generator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #base_url ⇒ String
- #class_name ⇒ String
- #exec ⇒ TrueClass, FalseClass
- #extension ⇒ String
- #file_name ⇒ String
- #file_path ⇒ String
-
#initialize(schema_path, options = {}) ⇒ Generator
constructor
A new instance of Generator.
- #original_schema ⇒ Aries::Schema
- #output_path ⇒ String
- #resources ⇒ Array<Aries::Presenters::ResourceSwift>
- #schema ⇒ Aries::Presenters::SchemaSwift
- #template ⇒ ERB
- #template_path ⇒ String
- #timestamp ⇒ Object
Constructor Details
#initialize(schema_path, options = {}) ⇒ Generator
Returns a new instance of Generator.
12 13 14 15 16 17 18 |
# File 'lib/aries/generator.rb', line 12 def initialize schema_path, ={} @schema_path = schema_path @output_path = [:output_path] || Dir.pwd @class_name = [:class_name] || "AriesApi" @language = [:language] || "swift" @base_url = [:base_url] end |
Class Method Details
.generate(schema_path, options) ⇒ Object
5 6 7 |
# File 'lib/aries/generator.rb', line 5 def self.generate schema_path, new(schema_path, ).exec end |
Instance Method Details
#base_url ⇒ String
57 58 59 |
# File 'lib/aries/generator.rb', line 57 def base_url @base_url || schema.base_url end |
#class_name ⇒ String
34 35 36 |
# File 'lib/aries/generator.rb', line 34 def class_name @class_name.camelcase end |
#exec ⇒ TrueClass, FalseClass
86 87 88 89 90 |
# 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 ⇒ String
44 45 46 47 48 49 |
# File 'lib/aries/generator.rb', line 44 def extension case @language when "swift" then "swift" when "java" then "java" end end |
#file_name ⇒ String
52 53 54 |
# File 'lib/aries/generator.rb', line 52 def file_name class_name + "." + extension end |
#file_path ⇒ String
72 73 74 |
# File 'lib/aries/generator.rb', line 72 def file_path output_path + "/" + file_name end |
#original_schema ⇒ Aries::Schema
29 30 31 |
# File 'lib/aries/generator.rb', line 29 def original_schema Schema.new JSON.parse(File.read(@schema_path)) end |
#output_path ⇒ String
39 40 41 |
# File 'lib/aries/generator.rb', line 39 def output_path @output_path end |
#resources ⇒ Array<Aries::Presenters::ResourceSwift>
62 63 64 |
# File 'lib/aries/generator.rb', line 62 def resources schema.resources end |
#schema ⇒ Aries::Presenters::SchemaSwift
21 22 23 24 25 26 |
# File 'lib/aries/generator.rb', line 21 def schema case @language when "swift" Aries::Presenters::SchemaSwift.new original_schema end end |
#template ⇒ ERB
77 78 79 |
# File 'lib/aries/generator.rb', line 77 def template Erubis::Eruby.new File.read(template_path), trim: true end |
#template_path ⇒ String
67 68 69 |
# File 'lib/aries/generator.rb', line 67 def template_path File.("../templates/client.#{@language}.erb", __FILE__) end |
#timestamp ⇒ Object
81 82 83 |
# File 'lib/aries/generator.rb', line 81 def Time.now.strftime('%Y/%m/%d') end |