Class: Aries::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/aries/generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema_path, options = {}) ⇒ Generator

Returns a new instance of Generator.

Parameters:

  • file_path (String)

    json schema file path



12
13
14
15
16
17
18
# 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

Class Method Details

.generate(schema_path, options) ⇒ Object



5
6
7
# File 'lib/aries/generator.rb', line 5

def self.generate schema_path, options
  new(schema_path, options).exec
end

Instance Method Details

#base_urlString

Returns:

  • (String)


57
58
59
# File 'lib/aries/generator.rb', line 57

def base_url
  @base_url || schema.base_url
end

#class_nameString

Returns:

  • (String)


34
35
36
# File 'lib/aries/generator.rb', line 34

def class_name
  @class_name.camelcase
end

#execTrueClass, FalseClass

Returns:

  • (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

#extensionString

Returns:

  • (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_nameString

Returns:

  • (String)


52
53
54
# File 'lib/aries/generator.rb', line 52

def file_name
  class_name + "." + extension
end

#file_pathString

Returns:

  • (String)


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

def file_path
  output_path + "/" + file_name
end

#original_schemaAries::Schema

Returns:



29
30
31
# File 'lib/aries/generator.rb', line 29

def original_schema
  Schema.new JSON.parse(File.read(@schema_path))
end

#output_pathString

Returns:

  • (String)


39
40
41
# File 'lib/aries/generator.rb', line 39

def output_path
  @output_path
end

#resourcesArray<Aries::Presenters::ResourceSwift>



62
63
64
# File 'lib/aries/generator.rb', line 62

def resources
  schema.resources
end

#schemaAries::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

#templateERB

Returns:

  • (ERB)


77
78
79
# File 'lib/aries/generator.rb', line 77

def template
  Erubis::Eruby.new File.read(template_path), trim: true
end

#template_pathString

Returns:

  • (String)


67
68
69
# File 'lib/aries/generator.rb', line 67

def template_path
  File.expand_path("../templates/client.#{@language}.erb", __FILE__)
end

#timestampObject



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

def timestamp
  Time.now.strftime('%Y/%m/%d')
end