expressir 0.2.17-x64-mingw32 → 0.2.18-x64-mingw32

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: 4de737c79608503c7a15d1ad1b6063a0b9a6ade2206c7d0b2c06b2f1da7c670d
4
- data.tar.gz: 15178e49df0a3286f900f047ebfea8d63645a21fa830b333c6d01812285889a1
3
+ metadata.gz: 74fbffaca7721129472a080630b58879825bb258d21167c9be56e6550a79218f
4
+ data.tar.gz: 1e16a2240c951ceca1f4b5efbbecb798dcd4081df42546b973e66079e4212abc
5
5
  SHA512:
6
- metadata.gz: 9567350f76985cd668519d1cdbb67e38dbb5277dd23fa0856bb18f684e62467110d605fab1b8cd35ef62ea1640e3254b24d77d2bba97dee2dfca62ed546f5a66
7
- data.tar.gz: 004fe65da77bca9d74a7a186de6fa9aff400224900f83bd41fcac128922ebe1a69d0a35888244549185c59c19c39ef7ea1a0522df3f87e5ea727c304555f1a42
6
+ metadata.gz: f7b9873a16fcbb596c8e64ce29fc343927922dc97fde81ee36e2412379e81986ee674981bf600534d84b301bc54540f26263cdcabca495f7a53ca86eb1fd700f
7
+ data.tar.gz: 365b91eca6706ac74aa977e9aad173e9a1a5d34c2285f49a6196db1daefb1cfaaeea2ed204bb10b74ad18adba9e2831545439f9de92264933a9c27e7ae209a6b
@@ -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: x64-mingw32
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