lutaml 0.2.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lutaml
4
+ class Engine
5
+ attr_accessor :input
6
+
7
+ def initialize(input:)
8
+ @input = input
9
+ end
10
+
11
+ def render(_type)
12
+ raise ArgumentError, "Implement render method"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ruby-graphviz"
4
+ require "lutaml/layout/engine"
5
+
6
+ module Lutaml
7
+ module Layout
8
+ class GraphVizEngine < Engine
9
+ def render(type)
10
+ Open3.popen3("dot -T#{type}") do |stdin, stdout, _stderr, _wait|
11
+ stdin.puts(input)
12
+ stdin.close
13
+ stdout.read
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,5 +1,3 @@
1
- require "jmespath"
2
-
3
1
  module Lutaml
4
2
  module LutamlPath
5
3
  class DocumentWrapper
@@ -9,11 +7,8 @@ module Lutaml
9
7
  @serialized_document = serialize_document(document)
10
8
  end
11
9
 
12
- # Method for traversing document` structure
13
- # example for lutaml: wrapper.find('//#main-doc/main-class/nested-class')
14
- # Need to return descendant of Lutaml::LutamlPath::EntryWrapper
15
- def find(path)
16
- JMESPath.search(path, serialized_document)
10
+ def to_liquid
11
+ serialized_document
17
12
  end
18
13
 
19
14
  protected
@@ -21,6 +16,29 @@ module Lutaml
21
16
  def serialize_document(_path)
22
17
  raise ArgumentError, "implement #serialize_document!"
23
18
  end
19
+
20
+ def serialize_value(attr_value)
21
+ if attr_value.is_a?(Array)
22
+ return attr_value.map(&method(:serialize_to_hash))
23
+ end
24
+
25
+ attr_value
26
+ end
27
+
28
+ def serialize_to_hash(object)
29
+ return object if [String, Integer, Float].include?(object.class)
30
+
31
+ object.instance_variables.each_with_object({}) do |var, res|
32
+ variable = object.instance_variable_get(var)
33
+ res[var.to_s.gsub("@", "")] = if variable.is_a?(Array)
34
+ variable.map do |n|
35
+ serialize_to_hash(n)
36
+ end
37
+ else
38
+ variable
39
+ end
40
+ end
41
+ end
24
42
  end
25
43
  end
26
44
  end
@@ -0,0 +1,53 @@
1
+ # require "lutaml/express"
2
+ require "lutaml/uml"
3
+ require "lutaml/uml/lutaml_path/document_wrapper"
4
+ # require "lutaml/express/lutaml_path/document_wrapper"
5
+
6
+ module Lutaml
7
+ class Parser
8
+ attr_reader :parse_type, :file
9
+
10
+ class << self
11
+ def parse(file, input_type = nil)
12
+ new(file, input_type).parse
13
+ end
14
+
15
+ def parse_into_document(file, input_type = nil)
16
+ new(file, input_type).parse_into_document
17
+ end
18
+ end
19
+
20
+ def initialize(file, input_type)
21
+ @parse_type = input_type ? input_type : File.extname(file.path)[1..-1]
22
+ @file = file
23
+ end
24
+
25
+ def parse
26
+ document = parse_into_document
27
+ document_wrapper(document)
28
+ end
29
+
30
+ def parse_into_document
31
+ case parse_type
32
+ # when "exp"
33
+ # Lutaml::Express::Parsers::Exp.parse(file)
34
+ when "lutaml"
35
+ Lutaml::Uml::Parsers::Dsl.parse(file)
36
+ when "yml"
37
+ Lutaml::Uml::Parsers::Yaml.parse(file.path)
38
+ else
39
+ raise ArgumentError, "Unsupported file format"
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def document_wrapper(document)
46
+ if parse_type == "exp"
47
+ return Lutaml::Express::LutamlPath::DocumentWrapper.new(document)
48
+ end
49
+
50
+ Lutaml::Uml::LutamlPath::DocumentWrapper.new(document)
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,15 @@
1
+ require "lutaml/lutaml_path/document_wrapper"
2
+
3
+ module Lutaml
4
+ module Uml
5
+ module LutamlPath
6
+ class DocumentWrapper < ::Lutaml::LutamlPath::DocumentWrapper
7
+ protected
8
+
9
+ def serialize_document(document)
10
+ serialize_to_hash(document)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module Lutaml
2
- VERSION = "0.2.0".freeze
2
+ VERSION = "0.4.0".freeze
3
3
  end
@@ -16,22 +16,24 @@ Gem::Specification.new do |spec|
16
16
  spec.metadata["changelog_uri"] = "https://github.com/lutaml/lutaml/releases"
17
17
 
18
18
  # Specify which files should be added to the gem when it is released.
19
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ # The `git ls-files -z` loads the files in the RubyGem
20
+ # that have been added into git.
20
21
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ `git ls-files -z`
23
+ .split("\x0")
24
+ .reject { |f| f.match(%r{^(test|spec|features)/}) }
22
25
  end
23
26
  spec.bindir = "exe"
24
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
28
  spec.require_paths = ["lib"]
26
29
 
30
+ # spec.add_runtime_dependency "lutaml-express", "~> 0.1.3"
31
+ spec.add_runtime_dependency "lutaml-uml", "~> 0.2.5"
27
32
  spec.add_runtime_dependency "thor", "~> 1.0"
28
- # spec.add_runtime_dependency "activesupport", "~> 5.0"
29
- # spec.add_runtime_dependency "lutaml-uml"
30
- # spec.add_runtime_dependency "lutaml-sysml"
31
- spec.add_development_dependency "jmespath", "~> 1.4"
32
33
  spec.add_development_dependency "nokogiri", "~> 1.10"
33
34
 
34
35
  spec.add_development_dependency "bundler", "~> 2.0"
36
+ spec.add_development_dependency "byebug"
35
37
  spec.add_development_dependency "pry", "~> 0.12.2"
36
38
  spec.add_development_dependency "rake", "~> 10.0"
37
39
  spec.add_development_dependency "rspec", "~> 3.0"
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lutaml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.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: 2020-10-26 00:00:00.000000000 Z
11
+ date: 2021-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: thor
14
+ name: lutaml-uml
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.0'
19
+ version: 0.2.5
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.0'
26
+ version: 0.2.5
27
27
  - !ruby/object:Gem::Dependency
28
- name: jmespath
28
+ name: thor
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.4'
34
- type: :development
33
+ version: '1.0'
34
+ type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.4'
40
+ version: '1.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: nokogiri
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '2.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: pry
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -125,21 +139,35 @@ dependencies:
125
139
  description: 'LutaML: data models in textual form'
126
140
  email:
127
141
  - open.source@ribose.com'
128
- executables: []
142
+ executables:
143
+ - lutaml
129
144
  extensions: []
130
145
  extra_rdoc_files: []
131
146
  files:
147
+ - ".github/workflows/macos.yml"
148
+ - ".github/workflows/ubuntu.yml"
149
+ - ".github/workflows/windows.yml"
132
150
  - ".gitignore"
133
151
  - ".rspec"
134
152
  - ".travis.yml"
135
153
  - CODE_OF_CONDUCT.md
136
154
  - Gemfile
137
- - README.md
155
+ - README.adoc
138
156
  - Rakefile
139
157
  - bin/console
140
158
  - bin/setup
159
+ - exe/lutaml
141
160
  - lib/lutaml.rb
161
+ - lib/lutaml/command_line.rb
162
+ - lib/lutaml/express/lutaml_path/document_wrapper.rb
163
+ - lib/lutaml/formatter.rb
164
+ - lib/lutaml/formatter/base.rb
165
+ - lib/lutaml/formatter/graphviz.rb
166
+ - lib/lutaml/layout/engine.rb
167
+ - lib/lutaml/layout/graph_viz_engine.rb
142
168
  - lib/lutaml/lutaml_path/document_wrapper.rb
169
+ - lib/lutaml/parser.rb
170
+ - lib/lutaml/uml/lutaml_path/document_wrapper.rb
143
171
  - lib/lutaml/version.rb
144
172
  - lutaml.gemspec
145
173
  homepage: https://github.com/lutaml/lutaml
@@ -164,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
192
  - !ruby/object:Gem::Version
165
193
  version: '0'
166
194
  requirements: []
167
- rubygems_version: 3.0.6
195
+ rubygems_version: 3.0.3
168
196
  signing_key:
169
197
  specification_version: 4
170
198
  summary: 'LutaML: data models in textual form'
data/README.md DELETED
@@ -1,40 +0,0 @@
1
- # Lutaml
2
-
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/lutaml`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'lutaml'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle install
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install lutaml
22
-
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
-
33
- ## Contributing
34
-
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/lutaml. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/lutaml/blob/master/CODE_OF_CONDUCT.md).
36
-
37
-
38
- ## Code of Conduct
39
-
40
- Everyone interacting in the Lutaml project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/lutaml/blob/master/CODE_OF_CONDUCT.md).