expressir 0.2.17-x86-linux → 0.2.18-x86-linux

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: 85881d47f6f0ae98d38e81923c841e53e01f7c0c1e5acc002d22dd2393d5b798
4
- data.tar.gz: 2a0a8c25dd8b7e468a0ff9d40e16c52a730c19075c4c15719c7edcfc95c3413f
3
+ metadata.gz: 937ca3946d428e24acae755e9e7e5e0b0db96f3b0604348ef3aaa8e233f3b7bd
4
+ data.tar.gz: f6b951c4609b18640cb4dbcbeaf72ed2e1c47389d5863945a2849bf454aa864b
5
5
  SHA512:
6
- metadata.gz: 886134f22089082f34cccba7ee85eac35a0969a8aa28416dceb75165e6fcc8be21bed1d7eefa25a7fc4aa844d16ace21babbfe65c0ded9531ea198d9b70d29fc
7
- data.tar.gz: 434341f651c7680a1583fef1e1373e54ba298117077f77677892ee14541c18cf1eef9b0e66e42e959f9f9039496db1bc8426cdc164c42bf6834f94edbc70d181
6
+ metadata.gz: 518b0d2ad6e746b56079203a98d51a230ef0bfb1b5971390f09e2363056664138fdd974d5ffed40647f3bc32610ae880506d9527510a10eff2b6a5bf56990a71
7
+ data.tar.gz: 7cacd6bbb553a377a604e04e83e2a2cf53192224c9430bb9be4b704a2cf9725e9d02136d4434f85964ec7be6973403611123f711dd9cf6574579571304842cdf
@@ -5,6 +5,7 @@ rescue LoadError
5
5
  require_relative "express_parser"
6
6
  end
7
7
  require 'expressir/express_exp/visitor'
8
+ require 'pathname'
8
9
 
9
10
  =begin
10
11
  char_stream = Antlr4::Runtime::CharStreams.from_string(input, 'String')
@@ -25,6 +26,8 @@ module Expressir
25
26
  module ExpressExp
26
27
  class Parser
27
28
  def self.from_file(file, options = {})
29
+ root_path = options[:root_path]
30
+
28
31
  input = File.read(file)
29
32
 
30
33
  parser = ::ExpressParser::Parser.parse(input)
@@ -34,7 +37,9 @@ module Expressir
34
37
  visitor = Visitor.new(parser.tokens, options)
35
38
  repository = visitor.visit(parse_tree)
36
39
 
37
- repository.schemas.each{|schema| schema.file = file}
40
+ repository.schemas.each do |schema|
41
+ schema.file = root_path ? Pathname.new(file).relative_path_from(root_path).to_s : File.basename(file)
42
+ end
38
43
 
39
44
  repository
40
45
  end
@@ -51,7 +56,9 @@ module Expressir
51
56
  schemas: schemas
52
57
  })
53
58
 
54
- repository.schemas.each{|schema| schema.parent = repository}
59
+ repository.schemas.each do |schema|
60
+ schema.parent = repository
61
+ end
55
62
 
56
63
  repository
57
64
  end
@@ -2,6 +2,9 @@ module Expressir
2
2
  module Model
3
3
  class ModelElement
4
4
  CLASS_KEY = '_class'
5
+ FILE_KEY = 'file'
6
+ PARENT_KEY = 'parent'
7
+ CHILDREN_BY_ID_KEY = 'children_by_id'
5
8
  SOURCE_KEY = 'source'
6
9
 
7
10
  attr_accessor :parent
@@ -11,7 +14,8 @@ module Expressir
11
14
  end
12
15
 
13
16
  def model_instance_variables
14
- instance_variables.select{|x| x != :@file && x != :@parent && x != :@children_by_id}
17
+ skip_variables = [FILE_KEY, PARENT_KEY, CHILDREN_BY_ID_KEY].map{|x| "@#{x}".to_sym}
18
+ instance_variables.select{|x| !skip_variables.include?(x)}
15
19
  end
16
20
 
17
21
  def path
@@ -88,11 +92,15 @@ module Expressir
88
92
  end
89
93
 
90
94
  def to_hash(options = {})
91
- include_empty = options[:include_empty] || !options[:skip_empty] # TODO: remove skip_empty
95
+ root_path = options[:root_path]
92
96
  formatter = options[:formatter]
97
+ include_empty = options[:include_empty] || !options[:skip_empty] # TODO: remove skip_empty
93
98
 
94
99
  hash = {}
95
100
  hash[CLASS_KEY] = self.class.name
101
+ if self.is_a? Schema and file
102
+ hash[FILE_KEY] = root_path ? File.expand_path("#{root_path}/#{file}") : file
103
+ end
96
104
 
97
105
  model_instance_variables.each_with_object(hash) do |variable, result|
98
106
  key = variable.to_s.sub(/^@/, '')
@@ -1,3 +1,3 @@
1
1
  module Expressir
2
- VERSION = "0.2.17".freeze
2
+ VERSION = "0.2.18".freeze
3
3
  end
@@ -2,6 +2,7 @@
2
2
  _class: Expressir::Model::Repository
3
3
  schemas:
4
4
  - _class: Expressir::Model::Schema
5
+ file: multiple.exp
5
6
  id: multiple_schema1
6
7
  interfaces:
7
8
  - _class: Expressir::Model::Interface
@@ -146,6 +147,7 @@ schemas:
146
147
  - _class: Expressir::Model::Expressions::SimpleReference
147
148
  id: missing_entity
148
149
  - _class: Expressir::Model::Schema
150
+ file: multiple.exp
149
151
  id: multiple_schema2
150
152
  entities:
151
153
  - _class: Expressir::Model::Entity
@@ -157,6 +159,7 @@ schemas:
157
159
  type:
158
160
  _class: Expressir::Model::Types::Boolean
159
161
  - _class: Expressir::Model::Schema
162
+ file: multiple.exp
160
163
  id: multiple_schema3
161
164
  entities:
162
165
  - _class: Expressir::Model::Entity
@@ -168,6 +171,7 @@ schemas:
168
171
  type:
169
172
  _class: Expressir::Model::Types::Boolean
170
173
  - _class: Expressir::Model::Schema
174
+ file: multiple.exp
171
175
  id: multiple_schema4
172
176
  entities:
173
177
  - _class: Expressir::Model::Entity
@@ -2,6 +2,7 @@
2
2
  _class: Expressir::Model::Repository
3
3
  schemas:
4
4
  - _class: Expressir::Model::Schema
5
+ file: remark.exp
5
6
  id: remark_schema
6
7
  remarks:
7
8
  - |-
@@ -2,6 +2,7 @@
2
2
  _class: Expressir::Model::Repository
3
3
  schemas:
4
4
  - _class: Expressir::Model::Schema
5
+ file: single.exp
5
6
  id: single_schema
6
7
  entities:
7
8
  - _class: Expressir::Model::Entity
@@ -2,6 +2,7 @@
2
2
  _class: Expressir::Model::Repository
3
3
  schemas:
4
4
  - _class: Expressir::Model::Schema
5
+ file: single.exp
5
6
  id: single_schema
6
7
  entities:
7
8
  - _class: Expressir::Model::Entity
@@ -0,0 +1,9 @@
1
+ ---
2
+ _class: Expressir::Model::Repository
3
+ schemas:
4
+ - _class: Expressir::Model::Schema
5
+ file: original/examples/syntax/single.exp
6
+ id: single_schema
7
+ entities:
8
+ - _class: Expressir::Model::Entity
9
+ id: empty_entity
@@ -2,6 +2,7 @@
2
2
  _class: Expressir::Model::Repository
3
3
  schemas:
4
4
  - _class: Expressir::Model::Schema
5
+ file: syntax.exp
5
6
  id: syntax_schema
6
7
  version:
7
8
  _class: Expressir::Model::Literals::String
@@ -1,3 +1,4 @@
1
+ require "yaml"
1
2
  require "spec_helper"
2
3
  require "expressir/express_exp/parser"
3
4
  require "expressir/express_exp/formatter"
@@ -83,15 +83,38 @@ RSpec.describe Expressir::ExpressExp::Parser do
83
83
 
84
84
  schemas = repo.schemas
85
85
  expect(schemas.count).to eq(5)
86
- expect(schemas[0].file).to eq(exp_files[0])
86
+ expect(schemas[0].file).to eq(exp_files[0].basename.to_s)
87
87
  expect(schemas[0].id).to eq("single_schema")
88
- expect(schemas[1].file).to eq(exp_files[1])
88
+ expect(schemas[1].file).to eq(exp_files[1].basename.to_s)
89
89
  expect(schemas[1].id).to eq("multiple_schema1")
90
- expect(schemas[2].file).to eq(exp_files[1])
90
+ expect(schemas[2].file).to eq(exp_files[1].basename.to_s)
91
91
  expect(schemas[2].id).to eq("multiple_schema2")
92
- expect(schemas[3].file).to eq(exp_files[1])
92
+ expect(schemas[3].file).to eq(exp_files[1].basename.to_s)
93
93
  expect(schemas[3].id).to eq("multiple_schema3")
94
- expect(schemas[4].file).to eq(exp_files[1])
94
+ expect(schemas[4].file).to eq(exp_files[1].basename.to_s)
95
+ expect(schemas[4].id).to eq("multiple_schema4")
96
+ end
97
+
98
+ it "parses multiple files with a root path (single.exp, multiple.exp)" do
99
+ exp_files = [
100
+ Expressir.root_path.join("original", "examples", "syntax", "single.exp"),
101
+ Expressir.root_path.join("original", "examples", "syntax", "multiple.exp")
102
+ ]
103
+ root_path = Expressir.root_path
104
+
105
+ repo = Expressir::ExpressExp::Parser.from_files(exp_files, root_path: root_path)
106
+
107
+ schemas = repo.schemas
108
+ expect(schemas.count).to eq(5)
109
+ expect(schemas[0].file).to eq(exp_files[0].relative_path_from(root_path).to_s)
110
+ expect(schemas[0].id).to eq("single_schema")
111
+ expect(schemas[1].file).to eq(exp_files[1].relative_path_from(root_path).to_s)
112
+ expect(schemas[1].id).to eq("multiple_schema1")
113
+ expect(schemas[2].file).to eq(exp_files[1].relative_path_from(root_path).to_s)
114
+ expect(schemas[2].id).to eq("multiple_schema2")
115
+ expect(schemas[3].file).to eq(exp_files[1].relative_path_from(root_path).to_s)
116
+ expect(schemas[3].id).to eq("multiple_schema3")
117
+ expect(schemas[4].file).to eq(exp_files[1].relative_path_from(root_path).to_s)
95
118
  expect(schemas[4].id).to eq("multiple_schema4")
96
119
  end
97
120
  end
@@ -1,15 +1,32 @@
1
+
2
+ require "yaml"
1
3
  require "spec_helper"
2
4
  require "expressir/express_exp/parser"
5
+ require "expressir/express_exp/formatter"
3
6
 
4
7
  RSpec.describe Expressir::Model::ModelElement do
5
8
  describe ".to_hash" do
9
+ it "exports an object with a root path (single.exp)" do
10
+ exp_file = Expressir.root_path.join("original", "examples", "syntax", "single.exp")
11
+ yaml_file = Expressir.root_path.join("original", "examples", "syntax", "single_root_path.yaml")
12
+ root_path = Expressir.root_path
13
+
14
+ repo = Expressir::ExpressExp::Parser.from_file(exp_file, root_path: root_path)
15
+
16
+ result = YAML.dump(repo.to_hash(skip_empty: true))
17
+ # File.write(yaml_file, result)
18
+ expected_result = File.read(yaml_file)
19
+
20
+ expect(result).to eq(expected_result)
21
+ end
22
+
6
23
  it "exports an object with a formatter (single.exp)" do
7
24
  exp_file = Expressir.root_path.join("original", "examples", "syntax", "single.exp")
8
25
  yaml_file = Expressir.root_path.join("original", "examples", "syntax", "single_formatted.yaml")
9
26
 
10
27
  repo = Expressir::ExpressExp::Parser.from_file(exp_file)
11
28
 
12
- result = YAML.dump(repo.to_hash(skip_empty: true, formatter: Expressir::ExpressExp::Formatter))
29
+ result = YAML.dump(repo.to_hash(formatter: Expressir::ExpressExp::Formatter, skip_empty: true))
13
30
  # File.write(yaml_file, result)
14
31
  expected_result = File.read(yaml_file)
15
32
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: expressir
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.17
4
+ version: 0.2.18
5
5
  platform: x86-linux
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-09 00:00:00.000000000 Z
11
+ date: 2021-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -332,6 +332,7 @@ files:
332
332
  - original/examples/syntax/single.yaml
333
333
  - original/examples/syntax/single_formatted.exp
334
334
  - original/examples/syntax/single_formatted.yaml
335
+ - original/examples/syntax/single_root_path.yaml
335
336
  - original/examples/syntax/syntax.exp
336
337
  - original/examples/syntax/syntax.yaml
337
338
  - original/examples/syntax/syntax_formatted.exp