Class: Suma::ExpressSchema
- Inherits:
-
Object
- Object
- Suma::ExpressSchema
- Defined in:
- lib/suma/express_schema.rb
Defined Under Namespace
Modules: Type
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#is_standalone_file ⇒ Object
Returns the value of attribute is_standalone_file.
-
#output_path ⇒ Object
Returns the value of attribute output_path.
-
#parsed ⇒ Object
Returns the value of attribute parsed.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #build_output_filename ⇒ Object
- #ensure_id_loaded ⇒ Object
- #filename_plain ⇒ Object
-
#initialize(id:, path:, output_path:, is_standalone_file: false) ⇒ ExpressSchema
constructor
A new instance of ExpressSchema.
- #save_exp(with_annotations: false) ⇒ Object
- #to_plain ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(id:, path:, output_path:, is_standalone_file: false) ⇒ ExpressSchema
Returns a new instance of ExpressSchema.
46 47 48 49 50 51 |
# File 'lib/suma/express_schema.rb', line 46 def initialize(id:, path:, output_path:, is_standalone_file: false) @path = Pathname.new(path). @id = id @output_path = output_path @is_standalone_file = is_standalone_file end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
44 45 46 |
# File 'lib/suma/express_schema.rb', line 44 def id @id end |
#is_standalone_file ⇒ Object
Returns the value of attribute is_standalone_file.
44 45 46 |
# File 'lib/suma/express_schema.rb', line 44 def is_standalone_file @is_standalone_file end |
#output_path ⇒ Object
Returns the value of attribute output_path.
44 45 46 |
# File 'lib/suma/express_schema.rb', line 44 def output_path @output_path end |
#parsed ⇒ Object
Returns the value of attribute parsed.
44 45 46 |
# File 'lib/suma/express_schema.rb', line 44 def parsed @parsed end |
#path ⇒ Object
Returns the value of attribute path.
44 45 46 |
# File 'lib/suma/express_schema.rb', line 44 def path @path end |
Instance Method Details
#build_output_filename ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'lib/suma/express_schema.rb', line 79 def build_output_filename if @is_standalone_file File.join(@output_path, "#{@id}.exp") else parent_dir = File.basename(File.dirname(@path)) File.join(@output_path, parent_dir, File.basename(@path)) end end |
#ensure_id_loaded ⇒ Object
75 76 77 |
# File 'lib/suma/express_schema.rb', line 75 def ensure_id_loaded parsed unless @id end |
#filename_plain ⇒ Object
70 71 72 73 |
# File 'lib/suma/express_schema.rb', line 70 def filename_plain ensure_id_loaded build_output_filename end |
#save_exp(with_annotations: false) ⇒ Object
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/suma/express_schema.rb', line 88 def save_exp(with_annotations: false) relative_path = Pathname.new(filename_plain).relative_path_from(Dir.pwd) schema_type = with_annotations ? "annotated" : "plain" Utils.log "Save #{schema_type} schema: #{relative_path}" FileUtils.mkdir_p(File.dirname(filename_plain)) content = with_annotations ? parsed.to_s(no_remarks: false) : to_plain File.write(filename_plain, content) end |
#to_plain ⇒ Object
66 67 68 |
# File 'lib/suma/express_schema.rb', line 66 def to_plain parsed.to_s(no_remarks: true) end |
#type ⇒ Object
53 54 55 |
# File 'lib/suma/express_schema.rb', line 53 def type @type ||= classify end |