lutaml 0.4.1.pre.alpha → 0.5.1

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: 9856bef749609c2186daef72d9cac2275abdf35dee480be0658700d20e0f9e31
4
- data.tar.gz: f5a0c9decbf6188da822b39655ee14d048387783b28d92a5fa280781e6c02a16
3
+ metadata.gz: e0d36cefb8c5f6affcb0d56b44ab5d1f807608d8676c372ebea115a1dbda9bd8
4
+ data.tar.gz: b1f11f6cb22a115973ada3e6bc9a86de14a22288f32c6caaef92187673e9deb2
5
5
  SHA512:
6
- metadata.gz: f4ccdf6b1a8ef299ce9a255b9615595f68ed6d07159808983451fe637cbda6747d71a03171c49d21f0b2797346e0daca0a9e94a8e55ca9614e734d54588a2b65
7
- data.tar.gz: 37e385085efc088644b1d582144e5436ad5e4310899f25f4fbfafa090302410d8ce3343601a9c2250b4ac57f3a073b1c996bdbcd982602d6c58a7fc0197c3321
6
+ metadata.gz: 1d61ed2509c43cb9e31f3b643eae02a317c0b1ccdbbf0692b81d19afbe0196141157bd5e2951b4380fd94ad2a0a0a2a644a05d98e98eeec9b9809ec1f14e19ae
7
+ data.tar.gz: 7fec19ce2c1b94d81b12e0fa687d960af66d0c305d5f43afb5bbd56c6da49b3c4f77fbe5959262c33eec878082206c17e85a8266436cb73429934ca4880e0ecc
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,50 +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
- SOURCE_CODE_ATTRIBUTE_NAME = "sourcecode".freeze
9
-
10
8
  protected
11
9
 
12
10
  def serialize_document(repository)
13
- repository.schemas.each_with_object({}) do |schema, res|
14
- res["schemas"] ||= []
15
- res[schema.id] = serialize_value(schema).merge(SOURCE_CODE_ATTRIBUTE_NAME => entity_source_code(schema))
16
- res["schemas"].push(res[schema.id])
17
- end
18
- end
19
-
20
- def serialize_value(object)
21
- object.instance_variables.each_with_object({}) do |var, res|
22
- variable = object.instance_variable_get(var)
23
- if variable.respond_to?(:to_hash)
24
- res[var.to_s.gsub("@", "")] = variable.to_hash.merge(SOURCE_CODE_ATTRIBUTE_NAME => entity_source_code(variable))
25
- elsif variable.is_a?(Array)
26
- res[var.to_s.gsub("@", "")] = variable.map do |entity|
27
- if entity.respond_to?(:to_hash)
28
- entity.to_hash.merge(SOURCE_CODE_ATTRIBUTE_NAME => entity_source_code(entity))
29
- else
30
- entity
31
- end
32
- end
33
- else
34
- res[var.to_s.gsub("@", "")] = variable
35
- end
36
- end
37
- end
38
-
39
- def merge_source_code_attr(serialized_entries, entities)
40
- serialized_entries.map do |serialized|
41
- entity = entities.detect { |n| n.id == serialized["id"] }
42
- serialized.merge(SOURCE_CODE_ATTRIBUTE_NAME => entity_source_code(entity))
43
- end
44
- end
45
-
46
- def entity_source_code(entity)
47
- Expressir::ExpressExp::Formatter.format(entity)
11
+ repository
12
+ .to_hash(formatter: Formatter)['schemas']
48
13
  end
49
14
  end
50
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
 
@@ -26,7 +27,7 @@ module Lutaml
26
27
  end
27
28
 
28
29
  def serialize_to_hash(object)
29
- return object if [String, Integer, Float, FalseClass, TrueClass, Symbol, NilClass].include?(object.class)
30
+ return object if [String, Integer, Float, FalseClass, TrueClass, Symbol, NilClass, Hash].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,7 @@ module Lutaml
35
36
  serialize_to_hash(n)
36
37
  end
37
38
  else
38
- if [String, Integer, Float, FalseClass, TrueClass, Symbol, NilClass].include?(variable.class) || var == :@parent
39
+ if [String, Integer, Float, FalseClass, TrueClass, Symbol, NilClass, Hash].include?(variable.class) || var == :@parent
39
40
  variable
40
41
  else
41
42
  serialize_to_hash(variable)
data/lib/lutaml/parser.rb CHANGED
@@ -2,39 +2,48 @@ require "lutaml/express"
2
2
  require "lutaml/uml"
3
3
  require "lutaml/uml/lutaml_path/document_wrapper"
4
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
39
  when "exp"
33
- Lutaml::Express::Parsers::Exp.parse(file)
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.1-alpha".freeze
2
+ VERSION = "0.5.1".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lutaml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1.pre.alpha
4
+ version: 0.5.1
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-02-09 00:00:00.000000000 Z
11
+ date: 2021-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lutaml-express
@@ -174,6 +174,7 @@ files:
174
174
  - lib/lutaml.rb
175
175
  - lib/lutaml/command_line.rb
176
176
  - lib/lutaml/express/lutaml_path/document_wrapper.rb
177
+ - lib/lutaml/express/lutaml_path/formatter.rb
177
178
  - lib/lutaml/formatter.rb
178
179
  - lib/lutaml/formatter/base.rb
179
180
  - lib/lutaml/formatter/graphviz.rb
@@ -202,9 +203,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
202
203
  version: '0'
203
204
  required_rubygems_version: !ruby/object:Gem::Requirement
204
205
  requirements:
205
- - - ">"
206
+ - - ">="
206
207
  - !ruby/object:Gem::Version
207
- version: 1.3.1
208
+ version: '0'
208
209
  requirements: []
209
210
  rubygems_version: 3.0.3
210
211
  signing_key: