expressir 0.2.18-x86-linux → 0.2.19-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: 937ca3946d428e24acae755e9e7e5e0b0db96f3b0604348ef3aaa8e233f3b7bd
4
- data.tar.gz: f6b951c4609b18640cb4dbcbeaf72ed2e1c47389d5863945a2849bf454aa864b
3
+ metadata.gz: be185d6f7a01f95362ff89930b160c9a813a42aa1509a38aa449eba7fd2b49b3
4
+ data.tar.gz: b838c6614cdd366bb0e40e24fe511703286650950b4bc8846dec14392ee8ff3b
5
5
  SHA512:
6
- metadata.gz: 518b0d2ad6e746b56079203a98d51a230ef0bfb1b5971390f09e2363056664138fdd974d5ffed40647f3bc32610ae880506d9527510a10eff2b6a5bf56990a71
7
- data.tar.gz: 7cacd6bbb553a377a604e04e83e2a2cf53192224c9430bb9be4b704a2cf9725e9d02136d4434f85964ec7be6973403611123f711dd9cf6574579571304842cdf
6
+ metadata.gz: 4c0069c383b3142b3bca99e700ad1acc1bd977c6c8562ca4914d991f0c94e80cd0caa0f0305eb7eede25f856d9880ff9a4ae9c3e4f8767c2c2ec71fa464b1a3b
7
+ data.tar.gz: 0bebd47d699457c866acf76cd98288658f45209ea1a66c1dfaf48cba0083eef71a45b3de39897228ed81c1969195399939226921b9a912d8d6efa6a0d65fec48
@@ -43,3 +43,8 @@ jobs:
43
43
  - run: bundle exec rake compile
44
44
 
45
45
  - run: bundle exec rake
46
+
47
+ - uses: actions/upload-artifact@v2
48
+ with:
49
+ name: express_parser-${{ matrix.os }}-${{ matrix.ruby }}
50
+ path: lib/expressir/express_exp/express_parser.so
@@ -5,7 +5,6 @@ rescue LoadError
5
5
  require_relative "express_parser"
6
6
  end
7
7
  require 'expressir/express_exp/visitor'
8
- require 'pathname'
9
8
 
10
9
  =begin
11
10
  char_stream = Antlr4::Runtime::CharStreams.from_string(input, 'String')
@@ -26,8 +25,6 @@ module Expressir
26
25
  module ExpressExp
27
26
  class Parser
28
27
  def self.from_file(file, options = {})
29
- root_path = options[:root_path]
30
-
31
28
  input = File.read(file)
32
29
 
33
30
  parser = ::ExpressParser::Parser.parse(input)
@@ -38,7 +35,7 @@ module Expressir
38
35
  repository = visitor.visit(parse_tree)
39
36
 
40
37
  repository.schemas.each do |schema|
41
- schema.file = root_path ? Pathname.new(file).relative_path_from(root_path).to_s : File.basename(file)
38
+ schema.file = file.to_s
42
39
  end
43
40
 
44
41
  repository
@@ -1,3 +1,5 @@
1
+ require 'pathname'
2
+
1
3
  module Expressir
2
4
  module Model
3
5
  class ModelElement
@@ -99,17 +101,17 @@ module Expressir
99
101
  hash = {}
100
102
  hash[CLASS_KEY] = self.class.name
101
103
  if self.is_a? Schema and file
102
- hash[FILE_KEY] = root_path ? File.expand_path("#{root_path}/#{file}") : file
104
+ hash[FILE_KEY] = root_path ? Pathname.new(file).relative_path_from(root_path).to_s : file
103
105
  end
104
106
 
105
- model_instance_variables.each_with_object(hash) do |variable, result|
107
+ model_instance_variables.each do |variable|
106
108
  key = variable.to_s.sub(/^@/, '')
107
109
  value = instance_variable_get(variable)
108
110
  empty = value.nil? || (value.is_a?(Array) && value.count == 0)
109
111
 
110
112
  # skip empty values
111
113
  if !empty or include_empty
112
- result[key] = if value.is_a? Array
114
+ hash[key] = if value.is_a? Array
113
115
  value.map do |value|
114
116
  if value.is_a? ModelElement
115
117
  value.to_hash(options)
@@ -132,21 +134,28 @@ module Expressir
132
134
  hash
133
135
  end
134
136
 
135
- def self.from_hash(hash)
137
+ def self.from_hash(hash, options = {})
138
+ root_path = options[:root_path]
139
+
136
140
  node_class = hash[CLASS_KEY]
137
- node_options = hash.select{|x| x != CLASS_KEY}.each_with_object({}) do |(variable, value), result|
141
+ node_options = {}
142
+ if node_class == 'Expressir::Model::Schema' and hash[FILE_KEY]
143
+ node_options[FILE_KEY.to_sym] = root_path ? File.expand_path("#{root_path}/#{hash[FILE_KEY]}") : hash[FILE_KEY]
144
+ end
145
+
146
+ hash.select{|x| x != CLASS_KEY && x != FILE_KEY}.each do |variable, value|
138
147
  key = variable.to_sym
139
148
 
140
- result[key] = if value.is_a? Array
149
+ node_options[key] = if value.is_a? Array
141
150
  value.map do |value|
142
151
  if value.is_a? Hash
143
- self.from_hash(value)
152
+ self.from_hash(value, options)
144
153
  else
145
154
  value
146
155
  end
147
156
  end
148
157
  elsif value.is_a? Hash
149
- self.from_hash(value)
158
+ self.from_hash(value, options)
150
159
  else
151
160
  value
152
161
  end
@@ -1,3 +1,3 @@
1
1
  module Expressir
2
- VERSION = "0.2.18".freeze
2
+ VERSION = "0.2.19".freeze
3
3
  end
@@ -2,7 +2,7 @@
2
2
  _class: Expressir::Model::Repository
3
3
  schemas:
4
4
  - _class: Expressir::Model::Schema
5
- file: multiple.exp
5
+ file: original/examples/syntax/multiple.exp
6
6
  id: multiple_schema1
7
7
  interfaces:
8
8
  - _class: Expressir::Model::Interface
@@ -147,7 +147,7 @@ schemas:
147
147
  - _class: Expressir::Model::Expressions::SimpleReference
148
148
  id: missing_entity
149
149
  - _class: Expressir::Model::Schema
150
- file: multiple.exp
150
+ file: original/examples/syntax/multiple.exp
151
151
  id: multiple_schema2
152
152
  entities:
153
153
  - _class: Expressir::Model::Entity
@@ -159,7 +159,7 @@ schemas:
159
159
  type:
160
160
  _class: Expressir::Model::Types::Boolean
161
161
  - _class: Expressir::Model::Schema
162
- file: multiple.exp
162
+ file: original/examples/syntax/multiple.exp
163
163
  id: multiple_schema3
164
164
  entities:
165
165
  - _class: Expressir::Model::Entity
@@ -171,7 +171,7 @@ schemas:
171
171
  type:
172
172
  _class: Expressir::Model::Types::Boolean
173
173
  - _class: Expressir::Model::Schema
174
- file: multiple.exp
174
+ file: original/examples/syntax/multiple.exp
175
175
  id: multiple_schema4
176
176
  entities:
177
177
  - _class: Expressir::Model::Entity
@@ -2,7 +2,7 @@
2
2
  _class: Expressir::Model::Repository
3
3
  schemas:
4
4
  - _class: Expressir::Model::Schema
5
- file: remark.exp
5
+ file: original/examples/syntax/remark.exp
6
6
  id: remark_schema
7
7
  remarks:
8
8
  - |-
@@ -2,7 +2,7 @@
2
2
  _class: Expressir::Model::Repository
3
3
  schemas:
4
4
  - _class: Expressir::Model::Schema
5
- file: single.exp
5
+ file: original/examples/syntax/single.exp
6
6
  id: single_schema
7
7
  entities:
8
8
  - _class: Expressir::Model::Entity
@@ -2,7 +2,7 @@
2
2
  _class: Expressir::Model::Repository
3
3
  schemas:
4
4
  - _class: Expressir::Model::Schema
5
- file: single.exp
5
+ file: original/examples/syntax/single.exp
6
6
  id: single_schema
7
7
  entities:
8
8
  - _class: Expressir::Model::Entity
@@ -2,7 +2,7 @@
2
2
  _class: Expressir::Model::Repository
3
3
  schemas:
4
4
  - _class: Expressir::Model::Schema
5
- file: syntax.exp
5
+ file: original/examples/syntax/syntax.exp
6
6
  id: syntax_schema
7
7
  version:
8
8
  _class: Expressir::Model::Literals::String
@@ -9,7 +9,7 @@ RSpec.describe Expressir::ExpressExp::Parser do
9
9
  yaml_file = Expressir.root_path.join("original", "examples", "syntax", "single.yaml")
10
10
 
11
11
  repo = Expressir::ExpressExp::Parser.from_file(exp_file)
12
- result = YAML.dump(repo.to_hash(skip_empty: true))
12
+ result = YAML.dump(repo.to_hash(root_path: Expressir.root_path, skip_empty: true))
13
13
  # File.write(yaml_file, result)
14
14
  expected_result = File.read(yaml_file)
15
15
 
@@ -21,7 +21,7 @@ RSpec.describe Expressir::ExpressExp::Parser do
21
21
  yaml_file = Expressir.root_path.join("original", "examples", "syntax", "multiple.yaml")
22
22
 
23
23
  repo = Expressir::ExpressExp::Parser.from_file(exp_file)
24
- result = YAML.dump(repo.to_hash(skip_empty: true))
24
+ result = YAML.dump(repo.to_hash(root_path: Expressir.root_path, skip_empty: true))
25
25
  # File.write(yaml_file, result)
26
26
  expected_result = File.read(yaml_file)
27
27
 
@@ -33,7 +33,7 @@ RSpec.describe Expressir::ExpressExp::Parser do
33
33
  yaml_file = Expressir.root_path.join("original", "examples", "syntax", "syntax.yaml")
34
34
 
35
35
  repo = Expressir::ExpressExp::Parser.from_file(exp_file)
36
- result = YAML.dump(repo.to_hash(skip_empty: true))
36
+ result = YAML.dump(repo.to_hash(root_path: Expressir.root_path, skip_empty: true))
37
37
  # File.write(yaml_file, result)
38
38
  expected_result = File.read(yaml_file)
39
39
 
@@ -45,7 +45,7 @@ RSpec.describe Expressir::ExpressExp::Parser do
45
45
  yaml_file = Expressir.root_path.join("original", "examples", "syntax", "remark.yaml")
46
46
 
47
47
  repo = Expressir::ExpressExp::Parser.from_file(exp_file)
48
- result = YAML.dump(repo.to_hash(skip_empty: true))
48
+ result = YAML.dump(repo.to_hash(root_path: Expressir.root_path, skip_empty: true))
49
49
  # File.write(yaml_file, result)
50
50
  expected_result = File.read(yaml_file)
51
51
 
@@ -83,38 +83,15 @@ 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].basename.to_s)
86
+ expect(schemas[0].file).to eq(exp_files[0].to_s)
87
87
  expect(schemas[0].id).to eq("single_schema")
88
- expect(schemas[1].file).to eq(exp_files[1].basename.to_s)
88
+ expect(schemas[1].file).to eq(exp_files[1].to_s)
89
89
  expect(schemas[1].id).to eq("multiple_schema1")
90
- expect(schemas[2].file).to eq(exp_files[1].basename.to_s)
90
+ expect(schemas[2].file).to eq(exp_files[1].to_s)
91
91
  expect(schemas[2].id).to eq("multiple_schema2")
92
- expect(schemas[3].file).to eq(exp_files[1].basename.to_s)
92
+ expect(schemas[3].file).to eq(exp_files[1].to_s)
93
93
  expect(schemas[3].id).to eq("multiple_schema3")
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)
94
+ expect(schemas[4].file).to eq(exp_files[1].to_s)
118
95
  expect(schemas[4].id).to eq("multiple_schema4")
119
96
  end
120
97
  end
@@ -6,27 +6,13 @@ require "expressir/express_exp/formatter"
6
6
 
7
7
  RSpec.describe Expressir::Model::ModelElement do
8
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
-
23
9
  it "exports an object with a formatter (single.exp)" do
24
10
  exp_file = Expressir.root_path.join("original", "examples", "syntax", "single.exp")
25
11
  yaml_file = Expressir.root_path.join("original", "examples", "syntax", "single_formatted.yaml")
26
12
 
27
13
  repo = Expressir::ExpressExp::Parser.from_file(exp_file)
28
14
 
29
- result = YAML.dump(repo.to_hash(formatter: Expressir::ExpressExp::Formatter, skip_empty: true))
15
+ result = YAML.dump(repo.to_hash(root_path: Expressir.root_path, formatter: Expressir::ExpressExp::Formatter, skip_empty: true))
30
16
  # File.write(yaml_file, result)
31
17
  expected_result = File.read(yaml_file)
32
18
 
@@ -39,9 +25,9 @@ RSpec.describe Expressir::Model::ModelElement do
39
25
  yaml_file = Expressir.root_path.join("original", "examples", "syntax", "single.yaml")
40
26
 
41
27
  input = YAML.load(File.read(yaml_file))
42
- repo = Expressir::Model::ModelElement.from_hash(input)
28
+ repo = Expressir::Model::ModelElement.from_hash(input, root_path: Expressir.root_path)
43
29
 
44
- result = YAML.dump(repo.to_hash(skip_empty: true))
30
+ result = YAML.dump(repo.to_hash(root_path: Expressir.root_path, skip_empty: true))
45
31
  expected_result = File.read(yaml_file)
46
32
 
47
33
  expect(result).to eq(expected_result)
@@ -51,9 +37,9 @@ RSpec.describe Expressir::Model::ModelElement do
51
37
  yaml_file = Expressir.root_path.join("original", "examples", "syntax", "multiple.yaml")
52
38
 
53
39
  input = YAML.load(File.read(yaml_file))
54
- repo = Expressir::Model::ModelElement.from_hash(input)
40
+ repo = Expressir::Model::ModelElement.from_hash(input, root_path: Expressir.root_path)
55
41
 
56
- result = YAML.dump(repo.to_hash(skip_empty: true))
42
+ result = YAML.dump(repo.to_hash(root_path: Expressir.root_path, skip_empty: true))
57
43
  expected_result = File.read(yaml_file)
58
44
 
59
45
  expect(result).to eq(expected_result)
@@ -63,9 +49,9 @@ RSpec.describe Expressir::Model::ModelElement do
63
49
  yaml_file = Expressir.root_path.join("original", "examples", "syntax", "syntax.yaml")
64
50
 
65
51
  input = YAML.load(File.read(yaml_file))
66
- repo = Expressir::Model::ModelElement.from_hash(input)
52
+ repo = Expressir::Model::ModelElement.from_hash(input, root_path: Expressir.root_path)
67
53
 
68
- result = YAML.dump(repo.to_hash(skip_empty: true))
54
+ result = YAML.dump(repo.to_hash(root_path: Expressir.root_path, skip_empty: true))
69
55
  expected_result = File.read(yaml_file)
70
56
 
71
57
  expect(result).to eq(expected_result)
@@ -75,9 +61,9 @@ RSpec.describe Expressir::Model::ModelElement do
75
61
  yaml_file = Expressir.root_path.join("original", "examples", "syntax", "remark.yaml")
76
62
 
77
63
  input = YAML.load(File.read(yaml_file))
78
- repo = Expressir::Model::ModelElement.from_hash(input)
64
+ repo = Expressir::Model::ModelElement.from_hash(input, root_path: Expressir.root_path)
79
65
 
80
- result = YAML.dump(repo.to_hash(skip_empty: true))
66
+ result = YAML.dump(repo.to_hash(root_path: Expressir.root_path, skip_empty: true))
81
67
  expected_result = File.read(yaml_file)
82
68
 
83
69
  expect(result).to eq(expected_result)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: expressir
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.18
4
+ version: 0.2.19
5
5
  platform: x86-linux
6
6
  authors:
7
7
  - Ribose Inc.
@@ -332,7 +332,6 @@ 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
336
335
  - original/examples/syntax/syntax.exp
337
336
  - original/examples/syntax/syntax.yaml
338
337
  - original/examples/syntax/syntax_formatted.exp
@@ -1,9 +0,0 @@
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