lutaml 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 84bb179e752bc157f0de4a59ea8cf88e9bd1fe4430726dcefcf63269d12c86fb
4
- data.tar.gz: a5f8917e80a33814b9cc6a9e3556b335da72fe05fd73e4d54dc294d1c4b6a27f
3
+ metadata.gz: 1927c6eca5571747313bd1f8f523fb7b7a469f3bb56c354e4fbdf3947c11ee8e
4
+ data.tar.gz: 52d43df8507b54408f5435033a385cf6f0d4ce6f2703a9ba308143dc24d0cb07
5
5
  SHA512:
6
- metadata.gz: 64b11704d20aff55c53cb6b1d857d346a6e9016b84b091581372c38b100a3d21d499685550e8d5a8b132e4cc7de5e8da37c3efd14ae325d119a207a76fc0feea
7
- data.tar.gz: f9800bc7e40536370807a3e4a3429d60dfa1f2fd728054adf6c9a8e73ba813b20bad80e22c85323309089eb41e1455806381513c139de1a99cc804ebb37378f2
6
+ metadata.gz: 22a613b2fc780af4aeaeb2b6977153f58b633335f241ff2c93fde544fbcb201d9ca8e46a866dc91b08607deac37c4bc1d1cd00c1f8f2dfc03ecbed1b7630791a
7
+ data.tar.gz: 700a0d0a1174c74632dc68c2b4f2c6265982e304cd1a30f1348323cb9646e9ae86d43ffb416cd9ff3b9c5b6ab0a438b4d524493f334cec32720f4025a1d3c362
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
+ gem "expressir"
4
+
3
5
  # Specify your gem's dependencies in lutaml.gemspec
4
6
  gemspec
data/README.adoc CHANGED
@@ -37,7 +37,9 @@ In order to parse files supported by lutaml extensions, use Lutaml::Parser.parse
37
37
  [source,ruby]
38
38
  ----
39
39
  # example.exp is an EXPRESS repository file
40
- Lutaml::Parser.parse(File.new("example.exp")) # will produce Lutaml::LutamlPath::DocumentWrapper object with serialized express repository
40
+ Lutaml::Parser.parse([File.new("example.exp")]) # will produce Lutaml::LutamlPath::DocumentWrapper object with serialized express repository
41
+ # example.yaml is an EXPRESS cache file
42
+ Lutaml::Parser.parse([File.new("example.yaml")], ::Lutaml::Parser::EXPRESS_CACHE_PARSE_TYPE)
41
43
  ----
42
44
 
43
45
  == With cli tool
@@ -88,6 +88,7 @@ module Lutaml
88
88
 
89
89
  document = Lutaml::Parser
90
90
  .parse_into_document(File.new(input_path), @input_format)
91
+ .first
91
92
  result = @formatter.format(document)
92
93
 
93
94
  if @output_path
@@ -1,57 +1,15 @@
1
1
  require "lutaml/lutaml_path/document_wrapper"
2
- require "expressir/express_exp/formatter"
2
+ require "lutaml/express/lutaml_path/formatter"
3
3
 
4
4
  module Lutaml
5
5
  module Express
6
6
  module LutamlPath
7
7
  class DocumentWrapper < ::Lutaml::LutamlPath::DocumentWrapper
8
- SCHEMA_ATTRIBUTES = %w[
9
- id
10
- constants
11
- declarations
12
- entities
13
- functions
14
- interfaces
15
- procedures
16
- remarks
17
- rules
18
- subtype_constraints
19
- types
20
- version
21
- ].freeze
22
- SOURCE_CODE_ATTRIBUTE_NAME = "sourcecode".freeze
23
-
24
8
  protected
25
9
 
26
10
  def serialize_document(repository)
27
- repository.schemas.each_with_object({}) do |schema, res|
28
- res["schemas"] ||= []
29
- serialized_schema = SCHEMA_ATTRIBUTES
30
- .each_with_object({}) do |name, nested_res|
31
- attr_value = schema.send(name)
32
- nested_res[name] = serialize_value(attr_value)
33
- if name == "entities"
34
- nested_res[name] = merge_source_code_attr(nested_res[name],
35
- attr_value)
36
- end
37
- end
38
- res[schema.id] = serialized_schema
39
- serialized_schema = serialized_schema
40
- .merge(SOURCE_CODE_ATTRIBUTE_NAME =>
41
- entity_source_code(schema))
42
- res["schemas"].push(serialized_schema)
43
- end
44
- end
45
-
46
- def merge_source_code_attr(serialized_entries, entities)
47
- serialized_entries.map do |serialized|
48
- entity = entities.detect { |n| n.id == serialized["id"] }
49
- serialized.merge(SOURCE_CODE_ATTRIBUTE_NAME => entity_source_code(entity))
50
- end
51
- end
52
-
53
- def entity_source_code(entity)
54
- Expressir::ExpressExp::Formatter.format(entity)
11
+ repository
12
+ .to_hash(formatter: Formatter)['schemas']
55
13
  end
56
14
  end
57
15
  end
@@ -0,0 +1,14 @@
1
+ require "expressir/express_exp/formatter"
2
+ require "expressir/express_exp/schema_head_formatter"
3
+ require "expressir/express_exp/hyperlink_formatter"
4
+
5
+ module Lutaml
6
+ module Express
7
+ module LutamlPath
8
+ class Formatter < Expressir::ExpressExp::Formatter
9
+ include Expressir::ExpressExp::SchemaHeadFormatter
10
+ include Expressir::ExpressExp::HyperlinkFormatter
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,9 +1,10 @@
1
1
  module Lutaml
2
2
  module LutamlPath
3
3
  class DocumentWrapper
4
- attr_reader :serialized_document
4
+ attr_reader :serialized_document, :original_document
5
5
 
6
6
  def initialize(document)
7
+ @original_document = document
7
8
  @serialized_document = serialize_document(document)
8
9
  end
9
10
 
@@ -22,11 +23,11 @@ module Lutaml
22
23
  return attr_value.map(&method(:serialize_to_hash))
23
24
  end
24
25
 
25
- attr_value
26
+ serialize_to_hash(attr_value)
26
27
  end
27
28
 
28
29
  def serialize_to_hash(object)
29
- return object if [String, Integer, Float].include?(object.class)
30
+ return object if [String, Integer, Float, FalseClass, TrueClass, Symbol, NilClass].include?(object.class)
30
31
 
31
32
  object.instance_variables.each_with_object({}) do |var, res|
32
33
  variable = object.instance_variable_get(var)
@@ -35,7 +36,11 @@ module Lutaml
35
36
  serialize_to_hash(n)
36
37
  end
37
38
  else
38
- variable
39
+ if [String, Integer, Float, FalseClass, TrueClass, Symbol, NilClass].include?(variable.class) || var == :@parent
40
+ variable
41
+ else
42
+ serialize_to_hash(variable)
43
+ end
39
44
  end
40
45
  end
41
46
  end
data/lib/lutaml/parser.rb CHANGED
@@ -1,40 +1,49 @@
1
- # require "lutaml/express"
1
+ require "lutaml/express"
2
2
  require "lutaml/uml"
3
3
  require "lutaml/uml/lutaml_path/document_wrapper"
4
- # require "lutaml/express/lutaml_path/document_wrapper"
4
+ require "lutaml/express/lutaml_path/document_wrapper"
5
+ require "expressir/express_exp/cache"
5
6
 
6
7
  module Lutaml
7
8
  class Parser
8
- attr_reader :parse_type, :file
9
+ EXPRESS_CACHE_PARSE_TYPE = "exp.cache".freeze
10
+
11
+ attr_reader :parse_type, :file_list
9
12
 
10
13
  class << self
11
- def parse(file, input_type = nil)
12
- new(file, input_type).parse
14
+ def parse(file_list, input_type = nil)
15
+ file_list = file_list.is_a?(Array) ? file_list : [file_list]
16
+ new(Array(file_list), input_type).parse
13
17
  end
14
18
 
15
- def parse_into_document(file, input_type = nil)
16
- new(file, input_type).parse_into_document
19
+ def parse_into_document(file_list, input_type = nil)
20
+ file_list = file_list.is_a?(Array) ? file_list : [file_list]
21
+ new(Array(file_list), input_type).parse_into_document
17
22
  end
18
23
  end
19
24
 
20
- def initialize(file, input_type)
21
- @parse_type = input_type ? input_type : File.extname(file.path)[1..-1]
22
- @file = file
25
+ def initialize(file_list, input_type)
26
+ @parse_type = input_type ? input_type : File.extname(file_list.first.path)[1..-1]
27
+ @file_list = file_list
23
28
  end
24
29
 
25
30
  def parse
26
- document = parse_into_document
27
- document_wrapper(document)
31
+ documents = parse_into_document
32
+ return [document_wrapper(documents)] if ["exp", EXPRESS_CACHE_PARSE_TYPE].include?(parse_type)
33
+
34
+ documents.map { |doc| document_wrapper(doc) }
28
35
  end
29
36
 
30
37
  def parse_into_document
31
38
  case parse_type
32
- # when "exp"
33
- # Lutaml::Express::Parsers::Exp.parse(file)
39
+ when "exp"
40
+ Expressir::ExpressExp::Parser.from_files(file_list.map(&:path))
41
+ when EXPRESS_CACHE_PARSE_TYPE
42
+ Expressir::ExpressExp::Cache.from_file(file_list.first.path)
34
43
  when "lutaml"
35
- Lutaml::Uml::Parsers::Dsl.parse(file)
44
+ file_list.map { |file| Lutaml::Uml::Parsers::Dsl.parse(file) }
36
45
  when "yml"
37
- Lutaml::Uml::Parsers::Yaml.parse(file.path)
46
+ file_list.map { |file| Lutaml::Uml::Parsers::Yaml.parse(file.path) }
38
47
  else
39
48
  raise ArgumentError, "Unsupported file format"
40
49
  end
@@ -43,7 +52,7 @@ module Lutaml
43
52
  private
44
53
 
45
54
  def document_wrapper(document)
46
- if parse_type == "exp"
55
+ if ["exp", EXPRESS_CACHE_PARSE_TYPE].include?(parse_type)
47
56
  return Lutaml::Express::LutamlPath::DocumentWrapper.new(document)
48
57
  end
49
58
 
@@ -1,3 +1,3 @@
1
1
  module Lutaml
2
- VERSION = "0.4.0".freeze
2
+ VERSION = "0.5.0".freeze
3
3
  end
data/lutaml.gemspec CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
28
  spec.require_paths = ["lib"]
29
29
 
30
- # spec.add_runtime_dependency "lutaml-express", "~> 0.1.3"
30
+ spec.add_runtime_dependency "lutaml-express", "~> 0.1.3"
31
31
  spec.add_runtime_dependency "lutaml-uml", "~> 0.2.5"
32
32
  spec.add_runtime_dependency "thor", "~> 1.0"
33
33
  spec.add_development_dependency "nokogiri", "~> 1.10"
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lutaml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-18 00:00:00.000000000 Z
11
+ date: 2021-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lutaml-express
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.3
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: lutaml-uml
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -160,6 +174,7 @@ files:
160
174
  - lib/lutaml.rb
161
175
  - lib/lutaml/command_line.rb
162
176
  - lib/lutaml/express/lutaml_path/document_wrapper.rb
177
+ - lib/lutaml/express/lutaml_path/formatter.rb
163
178
  - lib/lutaml/formatter.rb
164
179
  - lib/lutaml/formatter/base.rb
165
180
  - lib/lutaml/formatter/graphviz.rb