Class: Suma::ExpressSchema
- Inherits:
-
Object
- Object
- Suma::ExpressSchema
- Defined in:
- lib/suma/express_schema.rb
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
11 12 13 14 15 16 |
# File 'lib/suma/express_schema.rb', line 11 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.
9 10 11 |
# File 'lib/suma/express_schema.rb', line 9 def id @id end |
#is_standalone_file ⇒ Object
Returns the value of attribute is_standalone_file.
9 10 11 |
# File 'lib/suma/express_schema.rb', line 9 def is_standalone_file @is_standalone_file end |
#output_path ⇒ Object
Returns the value of attribute output_path.
9 10 11 |
# File 'lib/suma/express_schema.rb', line 9 def output_path @output_path end |
#parsed ⇒ Object
Returns the value of attribute parsed.
9 10 11 |
# File 'lib/suma/express_schema.rb', line 9 def parsed @parsed end |
#path ⇒ Object
Returns the value of attribute path.
9 10 11 |
# File 'lib/suma/express_schema.rb', line 9 def path @path end |
Instance Method Details
#build_output_filename ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/suma/express_schema.rb', line 51 def build_output_filename if @is_standalone_file # For standalone files, output directly to output_path File.join(@output_path, "#{@id}.exp") else # For manifest schemas, preserve directory structure # Note: @output_path already contains the category (resources/modules) File.join(@output_path, @id, File.basename(@path)) end end |
#ensure_id_loaded ⇒ Object
47 48 49 |
# File 'lib/suma/express_schema.rb', line 47 def ensure_id_loaded parsed unless @id end |
#filename_plain ⇒ Object
42 43 44 45 |
# File 'lib/suma/express_schema.rb', line 42 def filename_plain ensure_id_loaded build_output_filename end |
#save_exp(with_annotations: false) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/suma/express_schema.rb', line 62 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}" # return if File.exist?(filename_plain) 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
38 39 40 |
# File 'lib/suma/express_schema.rb', line 38 def to_plain parsed.to_s(no_remarks: true) end |
#type ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/suma/express_schema.rb', line 18 def type path_str = @path.to_s if path_str.include?("/resources/") "resources" elsif path_str.include?("/modules/") "modules" else "unknown_type" end end |