expressir 1.2.3-aarch64-linux

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. checksums.yaml +7 -0
  2. data/.cross_rubies +21 -0
  3. data/.github/workflows/rake.yml +96 -0
  4. data/.github/workflows/release.yml +120 -0
  5. data/.gitignore +17 -0
  6. data/.gitmodules +3 -0
  7. data/.hound.yml +3 -0
  8. data/.rspec +2 -0
  9. data/.rubocop.yml +8 -0
  10. data/.yardopts +11 -0
  11. data/Gemfile +4 -0
  12. data/README.adoc +147 -0
  13. data/Rakefile +14 -0
  14. data/bin/console +12 -0
  15. data/bin/rspec +29 -0
  16. data/bin/setup +8 -0
  17. data/demo.rb +18 -0
  18. data/docs/development.md +90 -0
  19. data/exe/expressir +20 -0
  20. data/exe/format +18 -0
  21. data/exe/format-test +81 -0
  22. data/exe/generate-parser +48 -0
  23. data/expressir.gemspec +46 -0
  24. data/lib/expressir/cli/ui.rb +36 -0
  25. data/lib/expressir/cli.rb +21 -0
  26. data/lib/expressir/config.rb +23 -0
  27. data/lib/expressir/express/2.7/express_parser.so +0 -0
  28. data/lib/expressir/express/3.0/express_parser.so +0 -0
  29. data/lib/expressir/express/3.1/express_parser.so +0 -0
  30. data/lib/expressir/express/cache.rb +51 -0
  31. data/lib/expressir/express/formatter.rb +1608 -0
  32. data/lib/expressir/express/hyperlink_formatter.rb +36 -0
  33. data/lib/expressir/express/model_visitor.rb +24 -0
  34. data/lib/expressir/express/parser.rb +81 -0
  35. data/lib/expressir/express/resolve_references_model_visitor.rb +31 -0
  36. data/lib/expressir/express/schema_head_formatter.rb +23 -0
  37. data/lib/expressir/express/visitor.rb +2574 -0
  38. data/lib/expressir/model/cache.rb +17 -0
  39. data/lib/expressir/model/data_type.rb +9 -0
  40. data/lib/expressir/model/data_types/aggregate.rb +31 -0
  41. data/lib/expressir/model/data_types/array.rb +31 -0
  42. data/lib/expressir/model/data_types/bag.rb +25 -0
  43. data/lib/expressir/model/data_types/binary.rb +22 -0
  44. data/lib/expressir/model/data_types/boolean.rb +10 -0
  45. data/lib/expressir/model/data_types/enumeration.rb +25 -0
  46. data/lib/expressir/model/data_types/enumeration_item.rb +26 -0
  47. data/lib/expressir/model/data_types/generic.rb +26 -0
  48. data/lib/expressir/model/data_types/generic_entity.rb +26 -0
  49. data/lib/expressir/model/data_types/integer.rb +10 -0
  50. data/lib/expressir/model/data_types/list.rb +28 -0
  51. data/lib/expressir/model/data_types/logical.rb +10 -0
  52. data/lib/expressir/model/data_types/number.rb +10 -0
  53. data/lib/expressir/model/data_types/real.rb +19 -0
  54. data/lib/expressir/model/data_types/select.rb +28 -0
  55. data/lib/expressir/model/data_types/set.rb +25 -0
  56. data/lib/expressir/model/data_types/string.rb +22 -0
  57. data/lib/expressir/model/declaration.rb +9 -0
  58. data/lib/expressir/model/declarations/attribute.rb +47 -0
  59. data/lib/expressir/model/declarations/constant.rb +34 -0
  60. data/lib/expressir/model/declarations/entity.rb +53 -0
  61. data/lib/expressir/model/declarations/function.rb +67 -0
  62. data/lib/expressir/model/declarations/interface.rb +28 -0
  63. data/lib/expressir/model/declarations/interface_item.rb +23 -0
  64. data/lib/expressir/model/declarations/interfaced_item.rb +37 -0
  65. data/lib/expressir/model/declarations/parameter.rb +34 -0
  66. data/lib/expressir/model/declarations/procedure.rb +64 -0
  67. data/lib/expressir/model/declarations/remark_item.rb +21 -0
  68. data/lib/expressir/model/declarations/rule.rb +71 -0
  69. data/lib/expressir/model/declarations/schema.rb +117 -0
  70. data/lib/expressir/model/declarations/schema_version.rb +22 -0
  71. data/lib/expressir/model/declarations/schema_version_item.rb +22 -0
  72. data/lib/expressir/model/declarations/subtype_constraint.rb +40 -0
  73. data/lib/expressir/model/declarations/type.rb +45 -0
  74. data/lib/expressir/model/declarations/unique_rule.rb +31 -0
  75. data/lib/expressir/model/declarations/variable.rb +34 -0
  76. data/lib/expressir/model/declarations/where_rule.rb +31 -0
  77. data/lib/expressir/model/expression.rb +9 -0
  78. data/lib/expressir/model/expressions/aggregate_initializer.rb +19 -0
  79. data/lib/expressir/model/expressions/aggregate_initializer_item.rb +22 -0
  80. data/lib/expressir/model/expressions/binary_expression.rb +53 -0
  81. data/lib/expressir/model/expressions/entity_constructor.rb +22 -0
  82. data/lib/expressir/model/expressions/function_call.rb +22 -0
  83. data/lib/expressir/model/expressions/interval.rb +34 -0
  84. data/lib/expressir/model/expressions/query_expression.rb +35 -0
  85. data/lib/expressir/model/expressions/unary_expression.rb +27 -0
  86. data/lib/expressir/model/identifier.rb +34 -0
  87. data/lib/expressir/model/literal.rb +9 -0
  88. data/lib/expressir/model/literals/binary.rb +19 -0
  89. data/lib/expressir/model/literals/integer.rb +19 -0
  90. data/lib/expressir/model/literals/logical.rb +23 -0
  91. data/lib/expressir/model/literals/real.rb +19 -0
  92. data/lib/expressir/model/literals/string.rb +22 -0
  93. data/lib/expressir/model/model_element.rb +208 -0
  94. data/lib/expressir/model/reference.rb +9 -0
  95. data/lib/expressir/model/references/attribute_reference.rb +22 -0
  96. data/lib/expressir/model/references/group_reference.rb +22 -0
  97. data/lib/expressir/model/references/index_reference.rb +27 -0
  98. data/lib/expressir/model/references/simple_reference.rb +24 -0
  99. data/lib/expressir/model/repository.rb +23 -0
  100. data/lib/expressir/model/statement.rb +9 -0
  101. data/lib/expressir/model/statements/alias.rb +35 -0
  102. data/lib/expressir/model/statements/assignment.rb +22 -0
  103. data/lib/expressir/model/statements/case.rb +25 -0
  104. data/lib/expressir/model/statements/case_action.rb +22 -0
  105. data/lib/expressir/model/statements/compound.rb +19 -0
  106. data/lib/expressir/model/statements/escape.rb +10 -0
  107. data/lib/expressir/model/statements/if.rb +25 -0
  108. data/lib/expressir/model/statements/null.rb +10 -0
  109. data/lib/expressir/model/statements/procedure_call.rb +22 -0
  110. data/lib/expressir/model/statements/repeat.rb +47 -0
  111. data/lib/expressir/model/statements/return.rb +19 -0
  112. data/lib/expressir/model/statements/skip.rb +10 -0
  113. data/lib/expressir/model/supertype_expression.rb +9 -0
  114. data/lib/expressir/model/supertype_expressions/binary_supertype_expression.rb +29 -0
  115. data/lib/expressir/model/supertype_expressions/oneof_supertype_expression.rb +19 -0
  116. data/lib/expressir/model.rb +79 -0
  117. data/lib/expressir/version.rb +3 -0
  118. data/lib/expressir.rb +20 -0
  119. data/original/examples/ap233/ap233e1_arm_lf_stepmod-2010-11-12.exp +9589 -0
  120. data/original/examples/ap233/ap233e1_arm_lf_stepmod-2010-11-12.owl +36619 -0
  121. data/original/examples/ap233/ap233e1_arm_lf_stepmod-2010-11-12.xml +13294 -0
  122. data/original/examples/employment/eclipse/.project +17 -0
  123. data/original/examples/employment/eclipse/Export/Employment.png +0 -0
  124. data/original/examples/employment/eclipse/Express/employment_schema.exp +33 -0
  125. data/original/examples/employment/eclipse/Express/employment_schema.xmi +77 -0
  126. data/original/examples/employment/eclipse/Express/employment_schema.xml +93 -0
  127. data/original/examples/employment/eclipse/Models/Employment.uml +4 -0
  128. data/original/examples/employment/eclipse/Models/Employment.umldi +240 -0
  129. data/original/examples/employment/eclipse/readme.txt +7 -0
  130. data/original/examples/employment/employment_schema.exp +33 -0
  131. data/original/examples/employment/employment_schema.rb +232 -0
  132. data/original/examples/employment/employment_schema.xml +93 -0
  133. data/original/examples/employment/employment_schema___module.rb +46 -0
  134. data/original/examples/employment/employment_schema___p28attr.rb +126 -0
  135. data/original/examples/employment/employment_schema___p28inst.rb +26 -0
  136. data/original/examples/employment/example_employment_data.xml +1 -0
  137. data/original/examples/employment/example_employment_data_copy.xml +1 -0
  138. data/original/examples/employment/example_employment_reader.rb +30 -0
  139. data/original/examples/employment/example_employment_writer.rb +51 -0
  140. data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.exp +3710 -0
  141. data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.owl +35880 -0
  142. data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.xmi +15357 -0
  143. data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.xml +9468 -0
  144. data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.exp +8404 -0
  145. data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.owl +43147 -0
  146. data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.xmi +18341 -0
  147. data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.xml +11632 -0
  148. data/original/exp2ruby.rb +525 -0
  149. data/original/expsm.rb +34 -0
  150. data/original/mapping_owl.rb +1018 -0
  151. data/original/mapping_sysml.rb +2281 -0
  152. data/original/mapping_uml2.rb +599 -0
  153. data/original/mapping_uml2_eclipse.rb +433 -0
  154. data/original/reeper.rb +134 -0
  155. data/rakelib/cross-ruby.rake +316 -0
  156. data/spec/acceptance/version_spec.rb +12 -0
  157. data/spec/expressir/express/cache_spec.rb +64 -0
  158. data/spec/expressir/express/formatter_spec.rb +127 -0
  159. data/spec/expressir/express/parser_spec.rb +98 -0
  160. data/spec/expressir/model/model_element_spec.rb +266 -0
  161. data/spec/expressr_spec.rb +5 -0
  162. data/spec/spec_helper.rb +17 -0
  163. data/spec/support/console_helper.rb +29 -0
  164. data/spec/syntax/multiple.exp +23 -0
  165. data/spec/syntax/multiple.yaml +198 -0
  166. data/spec/syntax/multiple_formatted.exp +71 -0
  167. data/spec/syntax/multiple_hyperlink_formatted.exp +71 -0
  168. data/spec/syntax/multiple_schema_head_hyperlink_formatted.exp +13 -0
  169. data/spec/syntax/remark.exp +191 -0
  170. data/spec/syntax/remark.yaml +466 -0
  171. data/spec/syntax/remark_formatted.exp +227 -0
  172. data/spec/syntax/single.exp +4 -0
  173. data/spec/syntax/single.yaml +18 -0
  174. data/spec/syntax/single_formatted.exp +10 -0
  175. data/spec/syntax/single_formatted.yaml +36 -0
  176. data/spec/syntax/syntax.exp +333 -0
  177. data/spec/syntax/syntax.yaml +3509 -0
  178. data/spec/syntax/syntax_formatted.exp +902 -0
  179. data/spec/syntax/syntax_hyperlink_formatted.exp +902 -0
  180. data/spec/syntax/syntax_schema_head_formatted.exp +18 -0
  181. metadata +398 -0
data/exe/format-test ADDED
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "yaml"
4
+ require "tempfile"
5
+ require "expressir/express/parser"
6
+ require "expressir/express/formatter"
7
+ require "expressir/express/schema_head_formatter"
8
+ require "expressir/express/hyperlink_formatter"
9
+ require "expressir/express/cache"
10
+
11
+ exp_files = [
12
+ # basic test
13
+ # '../iso-10303-stepmod/data/resources/action_schema/action_schema_annotated.exp',
14
+ # '../iso-10303-stepmod/data/resources/basic_attribute_schema/basic_attribute_schema_annotated.exp',
15
+ # '../iso-10303-stepmod/data/resources/support_resource_schema/support_resource_schema_annotated.exp',
16
+ # cyclic reference test
17
+ # '../iso-10303-stepmod/data/modules/analysis/mim_annotated.exp',
18
+ # '../iso-10303-stepmod/data/modules/analysis_product_relationships/mim_annotated.exp',
19
+ # cyclic reference test 2
20
+ # '../iso-10303-stepmod/data/resources/product_property_definition_schema/product_property_definition_schema_annotated.exp',
21
+ # '../iso-10303-stepmod/data/resources/product_property_representation_schema/product_property_representation_schema_annotated.exp',
22
+ # renamed reference test (36s)
23
+ # '../iso-10303-stepmod/ballots/ballots/ap210_wg12/express/resources/mathematical_functions_schema.exp',
24
+ # '../iso-10303-stepmod/data/resources/iso13584_expressions_schema/iso13584_expressions_schema.exp',
25
+ # annotated-express test (12s)
26
+ # see https://github.com/metanorma/annotated-express/blob/master/data/documents/resources/fundamentals_of_product_description_and_support/sections/04-schemas.adoc
27
+ '../iso-10303-stepmod/data/resources/action_schema/action_schema_annotated.exp',
28
+ '../iso-10303-stepmod/data/resources/application_context_schema/application_context_schema_annotated.exp',
29
+ '../iso-10303-stepmod/data/resources/approval_schema/approval_schema_annotated.exp',
30
+ '../iso-10303-stepmod/data/resources/basic_attribute_schema/basic_attribute_schema_annotated.exp',
31
+ '../iso-10303-stepmod/data/resources/certification_schema/certification_schema_annotated.exp',
32
+ '../iso-10303-stepmod/data/resources/contract_schema/contract_schema_annotated.exp',
33
+ '../iso-10303-stepmod/data/resources/date_time_schema/date_time_schema_annotated.exp',
34
+ '../iso-10303-stepmod/data/resources/document_schema/document_schema.exp',
35
+ '../iso-10303-stepmod/data/resources/effectivity_schema/effectivity_schema_annotated.exp',
36
+ '../iso-10303-stepmod/data/resources/experience_schema/experience_schema_annotated.exp',
37
+ '../iso-10303-stepmod/data/resources/external_reference_schema/external_reference_schema_annotated.exp',
38
+ '../iso-10303-stepmod/data/resources/group_schema/group_schema_annotated.exp',
39
+ '../iso-10303-stepmod/data/resources/language_schema/language_schema_annotated.exp',
40
+ '../iso-10303-stepmod/data/resources/location_schema/location_schema_annotated.exp',
41
+ '../iso-10303-stepmod/data/resources/management_resources_schema/management_resources_schema_annotated.exp',
42
+ '../iso-10303-stepmod/data/resources/measure_schema/measure_schema_annotated.exp',
43
+ '../iso-10303-stepmod/data/resources/person_organization_schema/person_organization_schema_annotated.exp',
44
+ '../iso-10303-stepmod/data/resources/process_property_schema/process_property_schema_annotated.exp',
45
+ '../iso-10303-stepmod/data/resources/product_definition_schema/product_definition_schema_annotated.exp',
46
+ '../iso-10303-stepmod/data/resources/product_property_definition_schema/product_property_definition_schema_annotated.exp',
47
+ '../iso-10303-stepmod/data/resources/product_property_representation_schema/product_property_representation_schema_annotated.exp',
48
+ '../iso-10303-stepmod/data/resources/qualifications_schema/qualifications_schema_annotated.exp',
49
+ '../iso-10303-stepmod/data/resources/security_classification_schema/security_classification_schema_annotated.exp',
50
+ '../iso-10303-stepmod/data/resources/support_resource_schema/support_resource_schema_annotated.exp',
51
+ # full test (6m18s + 8s = 6m26s)
52
+ # *`bundle exec ../stepmod-utils/exe/stepmod-find-express-files ../iso-10303-stepmod`.strip.split("\n").map{|file| File.exists?(file.sub(/\.exp$/, '_annotated.exp')) ? file.sub(/\.exp$/, '_annotated.exp') : file}
53
+ ]
54
+
55
+ start = Time.now
56
+ repository = Expressir::Express::Parser.from_files(exp_files)
57
+ puts "Parser.from_files time: #{(Time.now - start).round(2)}s"
58
+
59
+ temp_file = Tempfile.new
60
+ begin
61
+ start = Time.now
62
+ Expressir::Express::Cache.to_file(temp_file, repository)
63
+ puts "Cache.to_file time: #{(Time.now - start).round(2)}s"
64
+
65
+ start = Time.now
66
+ repository = Expressir::Express::Cache.from_file(temp_file)
67
+ puts "Cache.from_file time: #{(Time.now - start).round(2)}s"
68
+ ensure
69
+ temp_file.close
70
+ temp_file.unlink
71
+ end
72
+
73
+ start = Time.now
74
+ formatter = Class.new(Expressir::Express::Formatter) do
75
+ include Expressir::Express::SchemaHeadFormatter
76
+ include Expressir::Express::HyperlinkFormatter
77
+ end
78
+ result = repository.to_hash(formatter: formatter, skip_empty: true)
79
+ puts "Repository.to_hash time: #{(Time.now - start).round(2)}s"
80
+
81
+ # puts YAML.dump(result)
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'fileutils'
4
+ require 'antlr4-native'
5
+
6
+ grammar_file = ARGV.shift
7
+
8
+ # ANTLR does weird things if the grammar file isn't in the current working directory
9
+ temp_grammar_file = File.join(FileUtils.pwd(), File.basename(grammar_file))
10
+ FileUtils.cp(grammar_file, temp_grammar_file)
11
+
12
+ # generate parser
13
+ generator = Antlr4Native::Generator.new(
14
+ grammar_files: [File.basename(temp_grammar_file)],
15
+ output_dir: 'ext',
16
+ parser_root_method: 'syntax'
17
+ )
18
+ generator.generate
19
+
20
+ # fix issues with generated parser
21
+ parser_source_file = File.join(*%w(ext express-parser express_parser.cpp))
22
+ parser_source_lines = File.read(parser_source_file).split(/\n/)
23
+
24
+ # - add ParserProxy tokens method, simple compensation for missing exposed BufferedTokenStream
25
+ i = parser_source_lines.index{|x| x == ' Object syntax() {'}
26
+ parser_source_lines[i + 6] += "\n" + <<~CPP.split(/\n/).map{|x| x != "" ? " " + x : x}.join("\n") + "\n"
27
+ Array getTokens() {
28
+ Array a;
29
+
30
+ std::vector<Token*> tokens = this -> tokens -> getTokens();
31
+
32
+ for (auto &token : tokens) {
33
+ a.push(token);
34
+ }
35
+
36
+ return a;
37
+ }
38
+ CPP
39
+ i = parser_source_lines.index{|x| x == ' .define_method("syntax", &ParserProxy::syntax)'}
40
+ parser_source_lines[i] += "\n" + <<~CPP.split(/\n/).map{|x| x != "" ? " " + x : x}.join("\n")
41
+ .define_method("tokens", &ParserProxy::getTokens)
42
+ CPP
43
+
44
+ # write fixed parser file
45
+ File.write(parser_source_file, parser_source_lines.join("\n") + "\n")
46
+
47
+ # cleanup
48
+ FileUtils.rm(temp_grammar_file)
data/expressir.gemspec ADDED
@@ -0,0 +1,46 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "expressir/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "expressir"
7
+ spec.version = Expressir::VERSION
8
+ spec.authors = ["Ribose Inc."]
9
+ spec.email = ["open.source@ribose.com'"]
10
+
11
+ spec.summary = "ISO EXPRESS parser and tools in Ruby."
12
+ spec.description = "Expressir (“EXPRESS in Ruby”) is a Ruby parser for EXPRESS and a set of Ruby tools for accessing ISO EXPRESS data models."
13
+ spec.homepage = "https://github.com/lutaml/expressir"
14
+ spec.license = "MIT"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = spec.homepage
18
+ spec.metadata["changelog_uri"] = "https://github.com/lutaml/expressir/releases"
19
+
20
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
21
+
22
+ spec.files = `git ls-files`.split("\n")\
23
+ + Dir.glob('ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/**/*')
24
+
25
+ spec.test_files = `git ls-files -- {spec}/*`.split("\n")
26
+
27
+ spec.bindir = "exe"
28
+ spec.require_paths = ["lib"]
29
+ spec.executables = %w[expressir]
30
+
31
+ spec.extensions = File.join(*%w(ext express-parser extconf.rb))
32
+
33
+ spec.add_runtime_dependency "thor", "~> 1.0"
34
+ spec.add_runtime_dependency "rice", "~> 4.0.3"
35
+ spec.add_development_dependency "asciidoctor", "~> 2.0.13"
36
+ spec.add_development_dependency "antlr4-native", "~> 1.1.0"
37
+ spec.add_development_dependency "bundler", "~> 2.0"
38
+ spec.add_development_dependency "pry", "~> 0.12.2"
39
+ spec.add_development_dependency "byebug", "~> 11.1"
40
+ spec.add_development_dependency "rake", "~> 13.0"
41
+ spec.add_development_dependency "rake-compiler", "~> 1.1"
42
+ spec.add_development_dependency "rake-compiler-dock", "~> 1.1"
43
+ spec.add_development_dependency "rspec", "~> 3.0"
44
+ spec.add_development_dependency "yard", "~> 0.9.26"
45
+ spec.add_development_dependency "webrick", "~> 1.7.0"
46
+ end
@@ -0,0 +1,36 @@
1
+ require "thor"
2
+
3
+ module Expressir
4
+ module Cli
5
+ class UI < Thor
6
+ def self.ask(message)
7
+ new.ask(message)
8
+ end
9
+
10
+ def self.say(message)
11
+ new.say(message)
12
+ end
13
+
14
+ def self.error(message)
15
+ if log_types.include?("error")
16
+ new.error(message)
17
+ end
18
+ end
19
+
20
+ def self.info(message)
21
+ if log_types.include?("info")
22
+ new.say(message)
23
+ end
24
+ end
25
+
26
+ def self.run(command)
27
+ require "open3"
28
+ Open3.capture3(command)
29
+ end
30
+
31
+ def self.log_types
32
+ Expressir.configuration.logs.map(&:to_s) || []
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,21 @@
1
+ require "thor"
2
+ require "expressir/cli/ui"
3
+
4
+ module Expressir
5
+ module Cli
6
+ def self.ui
7
+ Expressir::Cli::UI
8
+ end
9
+
10
+ def self.start(args)
11
+ Base.start(args)
12
+ end
13
+
14
+ class Base < Thor
15
+ desc "version", "The Expressir Version"
16
+ def version
17
+ Cli.ui.say("Version #{Expressir::VERSION}")
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,23 @@
1
+ module Expressir
2
+ module Config
3
+ def configure
4
+ if block_given?
5
+ yield configuration
6
+ end
7
+ end
8
+
9
+ def configuration
10
+ @configuration ||= Configuration.new
11
+ end
12
+ end
13
+
14
+ class Configuration
15
+ attr_accessor :logs
16
+
17
+ def initialize
18
+ @logs ||= %i(error)
19
+ end
20
+ end
21
+
22
+ extend Config
23
+ end
@@ -0,0 +1,51 @@
1
+ require 'yaml'
2
+ require 'zlib'
3
+ require 'expressir/model'
4
+
5
+ module Expressir
6
+ module Express
7
+ class Cache
8
+ # Save Express model into a cache file
9
+ # @param file [String] cache file path
10
+ # @param content [Model::ModelElement] Express model
11
+ # @param root_path [String] Express repository root path, to be stripped from Express file paths to create a portable cache file
12
+ # @param test_overwrite_version [String] don't use, only for tests
13
+ # @return [nil]
14
+ def self.to_file(file, content, root_path: nil, test_overwrite_version: nil)
15
+ version = test_overwrite_version || VERSION
16
+
17
+ cache = Model::Cache.new(
18
+ version: version,
19
+ content: content
20
+ )
21
+
22
+ hash = cache.to_hash(root_path: root_path)
23
+ yaml = YAML.dump(hash)
24
+ yaml_compressed = Zlib::Deflate.deflate(yaml)
25
+
26
+ File.binwrite(file, yaml_compressed)
27
+ nil
28
+ end
29
+
30
+ # Load Express model from a cache file
31
+ # @param file [String] cache file path
32
+ # @param root_path [String] Express repository root path, to be prepended to Express file paths if loading a portable cache file
33
+ # @param test_overwrite_version [String] don't use, only for tests
34
+ # @return [Model::ModelElement] Express model
35
+ def self.from_file(file, root_path: nil, test_overwrite_version: nil)
36
+ version = test_overwrite_version || VERSION
37
+
38
+ yaml_compressed = File.binread(file)
39
+ yaml = Zlib::Inflate.inflate(yaml_compressed)
40
+ hash = YAML.load(yaml)
41
+ cache = Model::ModelElement.from_hash(hash, root_path: root_path)
42
+
43
+ if cache.version != version
44
+ raise Error.new("Cache version mismatch, cache version is #{cache.version}, Expressir version is #{version}")
45
+ end
46
+
47
+ cache.content
48
+ end
49
+ end
50
+ end
51
+ end