Class: Suma::ExpressSchema

Inherits:
Object
  • Object
show all
Defined in:
lib/suma/express_schema.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, path:, output_path:) ⇒ ExpressSchema

Returns a new instance of ExpressSchema.



11
12
13
14
15
# File 'lib/suma/express_schema.rb', line 11

def initialize(id:, path:, output_path:)
  @path = Pathname.new(path).expand_path
  @id = id
  @output_path = output_path
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#output_pathObject

Returns the value of attribute output_path.



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

def output_path
  @output_path
end

#parsedObject

Returns the value of attribute parsed.



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

def parsed
  @parsed
end

#pathObject

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#filename_plainObject



41
42
43
# File 'lib/suma/express_schema.rb', line 41

def filename_plain
  File.join(@output_path, type, id, File.basename(@path))
end

#save_expObject



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/suma/express_schema.rb', line 45

def save_exp
  relative_path = Pathname.new(filename_plain).relative_path_from(Dir.pwd)
  Utils.log "Save plain schema: #{relative_path}"

  # return if File.exist?(filename_plain)
  FileUtils.mkdir_p(File.dirname(filename_plain))

  File.open(filename_plain, "w") do |file|
    file.write(to_plain)
  end
end

#to_plainObject



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

def to_plain
  parsed.to_s(no_remarks: true)
end

#typeObject



17
18
19
20
21
22
23
24
25
26
# File 'lib/suma/express_schema.rb', line 17

def type
  case @path.to_s
  when %r{.*/resources/.*}
    "resources"
  when %r{.*/modules/.*}
    "modules"
  else
    "unknown_type"
  end
end