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.
47 48 49 50 51 52 |
# File 'lib/suma/express_schema.rb', line 47 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.
45 46 47 |
# File 'lib/suma/express_schema.rb', line 45 def id @id end |
#is_standalone_file ⇒ Object
Returns the value of attribute is_standalone_file.
45 46 47 |
# File 'lib/suma/express_schema.rb', line 45 def is_standalone_file @is_standalone_file end |
#output_path ⇒ Object
Returns the value of attribute output_path.
45 46 47 |
# File 'lib/suma/express_schema.rb', line 45 def output_path @output_path end |
#parsed ⇒ Object
Returns the value of attribute parsed.
45 46 47 |
# File 'lib/suma/express_schema.rb', line 45 def parsed @parsed end |
#path ⇒ Object
Returns the value of attribute path.
45 46 47 |
# File 'lib/suma/express_schema.rb', line 45 def path @path end |
Instance Method Details
#build_output_filename ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/suma/express_schema.rb', line 80 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
76 77 78 |
# File 'lib/suma/express_schema.rb', line 76 def ensure_id_loaded parsed unless @id end |
#filename_plain ⇒ Object
71 72 73 74 |
# File 'lib/suma/express_schema.rb', line 71 def filename_plain ensure_id_loaded build_output_filename end |
#save_exp(with_annotations: false) ⇒ Object
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/suma/express_schema.rb', line 89 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
67 68 69 |
# File 'lib/suma/express_schema.rb', line 67 def to_plain parsed.to_s(no_remarks: true) end |
#type ⇒ Object
54 55 56 |
# File 'lib/suma/express_schema.rb', line 54 def type @type ||= classify end |