lutaml-xmi 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3945e4e96c67e7436534710a4509f1840c27ce886b3b214493e1a50bbc11e673
4
+ data.tar.gz: adbef1d7784d7aa82ae7341966ed2d44fce3a6a800f64d584d93a3b903dd35ff
5
+ SHA512:
6
+ metadata.gz: 3d3865a7cbb8d8d0ca56ac26e662d0edc63677f8579e59d36a521c8d945f64a2579dd6b4c646b140f3f45c2f7d843ed1a19617a2076e95c40985cae5a2a3b862
7
+ data.tar.gz: 5fdb6a5c25badd0e82c0d2292d406801af7c88add9e5f1bd9b98c0c1b56e3856d604e48b3f65b69cc6212228adc3447bd10638ea87d378749655540a47d043fa
@@ -0,0 +1,36 @@
1
+ name: macos
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ paths-ignore:
8
+ - .github/workflows/ubuntu.yml
9
+ - .github/workflows/windows.yml
10
+
11
+ jobs:
12
+ test-macos:
13
+ name: Test on Ruby ${{ matrix.ruby }} macOS
14
+ runs-on: macos-latest
15
+ continue-on-error: ${{ matrix.experimental }}
16
+ strategy:
17
+ fail-fast: false
18
+ matrix:
19
+ ruby: [ '2.6', '2.5' ]
20
+ experimental: [false]
21
+ include:
22
+ - ruby: '2.7'
23
+ experimental: true
24
+ steps:
25
+ - uses: actions/checkout@master
26
+ - name: Use Ruby
27
+ uses: actions/setup-ruby@v1
28
+ with:
29
+ ruby-version: ${{ matrix.ruby }}
30
+ - name: Update gems
31
+ run: |
32
+ sudo gem install bundler --force
33
+ bundle install --jobs 4 --retry 3
34
+ - name: Run specs
35
+ run: |
36
+ bundle exec rake
@@ -0,0 +1,38 @@
1
+ name: ubuntu
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ tags:
7
+ - '*'
8
+ pull_request:
9
+ paths-ignore:
10
+ - .github/workflows/macos.yml
11
+ - .github/workflows/windows.yml
12
+
13
+ jobs:
14
+ test-linux:
15
+ name: Test on Ruby ${{ matrix.ruby }} Ubuntu
16
+ runs-on: ubuntu-latest
17
+ continue-on-error: ${{ matrix.experimental }}
18
+ strategy:
19
+ fail-fast: false
20
+ matrix:
21
+ ruby: [ '2.6', '2.5' ]
22
+ experimental: [false]
23
+ include:
24
+ - ruby: '2.7'
25
+ experimental: true
26
+ steps:
27
+ - uses: actions/checkout@master
28
+ - name: Use Ruby
29
+ uses: actions/setup-ruby@v1
30
+ with:
31
+ ruby-version: ${{ matrix.ruby }}
32
+ - name: Update gems
33
+ run: |
34
+ gem install bundler
35
+ bundle install --jobs 4 --retry 3
36
+ - name: Run specs
37
+ run: |
38
+ bundle exec rake
@@ -0,0 +1,41 @@
1
+ name: windows
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ paths-ignore:
8
+ - .github/workflows/macos.yml
9
+ - .github/workflows/ubuntu.yml
10
+
11
+ jobs:
12
+ test-windows:
13
+ name: Test on Ruby ${{ matrix.ruby }} Windows
14
+ runs-on: windows-latest
15
+ continue-on-error: ${{ matrix.experimental }}
16
+ strategy:
17
+ fail-fast: false
18
+ matrix:
19
+ ruby: [ '2.6', '2.5' ]
20
+ experimental: [false]
21
+ # Does not supported yet:
22
+ # Ruby (< 2.7.dev, >= 2.3), which is required by gem 'nokogiri (~> 1.10)', is not
23
+ # available in the local ruby installation
24
+ # include:
25
+ # - ruby: '2.7'
26
+ # experimental: true
27
+ steps:
28
+ - uses: actions/checkout@master
29
+ - name: Use Ruby
30
+ uses: actions/setup-ruby@v1
31
+ with:
32
+ ruby-version: ${{ matrix.ruby }}
33
+ - name: Update gems
34
+ shell: pwsh
35
+ run: |
36
+ gem install bundler
37
+ bundle config --local path vendor/bundle
38
+ bundle install --jobs 4 --retry 3
39
+ - name: Run specs
40
+ run: |
41
+ bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at ronald.tse@ribose.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in lutaml-uml.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 12.0"
data/README.adoc ADDED
@@ -0,0 +1,24 @@
1
+ # Lutaml::Uml
2
+
3
+ Lutaml-xmi is a parser for XML Metadata Interchange (XMI) Specification files.
4
+
5
+ ## Install
6
+
7
+ ### Bundler: `gem "lutaml-xmi"`
8
+
9
+ ### RubyGems: `gem install lutaml-xmi`
10
+
11
+ ## Development
12
+
13
+ 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.
14
+
15
+ 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).
16
+
17
+ ## Contributing
18
+
19
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/lutaml-xmi. 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-xmi/blob/master/CODE_OF_CONDUCT.md).
20
+
21
+
22
+ ## Code of Conduct
23
+
24
+ Everyone interacting in the Lutaml::Uml project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/lutaml-xmi/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "lutaml/xmi"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/lutaml/xmi.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "lutaml/xmi/version"
2
+ require "lutaml/xmi/parsers/xml"
3
+
4
+ module Lutaml
5
+ module XMI
6
+ end
7
+ end
@@ -0,0 +1,111 @@
1
+ require "nokogiri"
2
+ require "lutaml/uml/has_attributes"
3
+ require "lutaml/uml/document"
4
+
5
+ module Lutaml
6
+ module XMI
7
+ module Parsers
8
+ # Class for parsing .xmi schema files into ::Lutaml::Uml::Document
9
+ class XML
10
+ ATTRIBUTE_MAPPINGS = {
11
+ "uml:LiteralInteger" => "1",
12
+ "uml:LiteralUnlimitedNatural" => "*"
13
+ }
14
+ attr_reader :main_model
15
+
16
+ # @param [String] io - file object with path to .xmi file
17
+ # [Hash] options - options for parsing
18
+ #
19
+ # @return [Lutaml::XMI::Model::Document]
20
+ def self.parse(io, options = {})
21
+ new.parse(Nokogiri::XML(io.read))
22
+ end
23
+
24
+ def parse(xmi_doc)
25
+ @main_model = xmi_doc
26
+ ::Lutaml::Uml::Document
27
+ .new(serialize_to_hash(xmi_doc))
28
+ end
29
+
30
+ private
31
+
32
+ def serialize_to_hash(xmi_doc)
33
+ main_model = xmi_doc.xpath('//uml:Model[@xmi:type="uml:Model"]').first
34
+ {
35
+ name: main_model["name"],
36
+ classes: serialize_model_classes(main_model),
37
+ enums: serialize_model_enums(main_model)
38
+ # associations: serialize_model_associations(main_model)
39
+ }
40
+ end
41
+
42
+ def serialize_model_classes(model)
43
+ model.xpath('.//packagedElement[@xmi:type="uml:Class"]').map do |klass|
44
+ {
45
+ xmi_id: klass['xmi:id'],
46
+ xmi_uuid: klass['xmi:uuid'],
47
+ name: klass['name'],
48
+ attributes: serialize_class_attributes(klass),
49
+ associations: serialize_model_associations(klass)
50
+ }
51
+ end
52
+ end
53
+
54
+ def serialize_model_enums(model)
55
+ model.xpath('.//packagedElement[@xmi:type="uml:Enumeration"]').map do |enum|
56
+ attributes = enum
57
+ .xpath('.//ownedLiteral[@xmi:type="uml:EnumerationLiteral"]')
58
+ .map do |attribute|
59
+ {
60
+ # TODO: xmi_id
61
+ # xmi_id: enum['xmi:id'],
62
+ type: attribute['name'],
63
+ }
64
+ end
65
+ {
66
+ xmi_id: enum['xmi:id'],
67
+ xmi_uuid: enum['xmi:uuid'],
68
+ name: enum['name'],
69
+ attributes: attributes
70
+ }
71
+ end
72
+ end
73
+
74
+ def serialize_model_associations(klass)
75
+ return unless klass.attributes['name']
76
+
77
+ klass.xpath('.//ownedAttribute/type').map do |assoc|
78
+ if assoc.attributes && assoc.attributes['idref']
79
+ id_ref = assoc.attributes['idref'].value
80
+ linked_class = main_model.xpath(%Q(//packagedElement[@xmi:type="uml:Class" and @xmi:id="#{id_ref}"])).first
81
+ member_end = linked_class.attributes['name'].value if linked_class
82
+ end
83
+ if member_end
84
+ {
85
+ xmi_id: assoc['xmi:id'],
86
+ xmi_uuid: assoc['xmi:uuid'],
87
+ name: assoc['name'],
88
+ member_end: member_end
89
+ }
90
+ end
91
+ end.compact
92
+ end
93
+
94
+ def serialize_class_attributes(klass)
95
+ klass.xpath('.//ownedAttribute[@xmi:type="uml:Property"]').map do |attribute|
96
+ type = attribute.xpath('.//type').first || {}
97
+ lowerValue = attribute.xpath('.//lowerValue').first || {}
98
+ upperValue = attribute.xpath('.//upperValue').first || {}
99
+ {
100
+ # TODO: xmi_id
101
+ # xmi_id: klass['xmi:id'],
102
+ name: attribute['name'],
103
+ type: type['xmi:idref'],
104
+ cardinality: [ATTRIBUTE_MAPPINGS[lowerValue["xmi:type"]], ATTRIBUTE_MAPPINGS[upperValue["xmi:type"]]].compact
105
+ }
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,5 @@
1
+ module Lutaml
2
+ module XMI
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/lutaml/xmi/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "lutaml-xmi"
7
+ spec.version = Lutaml::XMI::VERSION
8
+ spec.authors = ["Ribose Inc."]
9
+ spec.email = ["open.source@ribose.com'"]
10
+
11
+ spec.summary = "XML Metadata Interchange (XMI) Specification parser in Ruby, tools for accessing EXPRESS data models."
12
+ spec.description = "XML Metadata Interchange (XMI) Specification parser in Ruby, tools for accessing EXPRESS data models."
13
+ spec.homepage = "https://github.com/lutaml/lutaml-xmi"
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/lutaml-xmi/releases"
19
+
20
+ spec.files = `git ls-files`.split("\n")
21
+ spec.test_files = `git ls-files -- {spec}/*`.split("\n")
22
+
23
+ spec.bindir = "exe"
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_runtime_dependency "hashie", "~> 4.1.0"
27
+ spec.add_runtime_dependency "thor", "~> 1.0"
28
+ spec.add_runtime_dependency "lutaml-uml", "~> 0.2"
29
+
30
+ spec.add_development_dependency "bundler", "~> 2.0"
31
+ spec.add_development_dependency "byebug"
32
+ spec.add_development_dependency "nokogiri", "~> 1.10"
33
+ spec.add_development_dependency "pry", "~> 0.12.2"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec", "~> 3.0"
36
+ spec.add_development_dependency "rubocop", "~> 0.54.0"
37
+ end