expressir 0.2.10-x86-linux → 0.2.11-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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5961c268267212e63da6edff1351ef7c9d8d3b52dc1d99d0d4843d7a92123078
|
4
|
+
data.tar.gz: 7b5365059b79b01fa2e46562f39d494f12236ba237745ccbff44bd9477f2e1bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93e0a0f3eb42f0570c1d075d22747d414321037a90f61e9ed96515eb41b4177ff19cace1429b348a36be57ed1c91e6d1e707ec68fcbe436d228f3f894247d58e
|
7
|
+
data.tar.gz: 18e429434ac5546908c84cc3d4713dfbe8d9af6f8dca2e03a50cb135f47242451e8f954240d75c0bca159634b6491767703b103b20b9f424be385c324c2d63a2
|
@@ -46,7 +46,7 @@ module Expressir
|
|
46
46
|
def visit(ctx)
|
47
47
|
result = super(ctx)
|
48
48
|
attach_source(ctx, result)
|
49
|
-
attach_parent(
|
49
|
+
attach_parent(result)
|
50
50
|
attach_remarks(ctx, result)
|
51
51
|
result
|
52
52
|
end
|
@@ -124,13 +124,9 @@ module Expressir
|
|
124
124
|
end
|
125
125
|
end
|
126
126
|
|
127
|
-
def attach_parent(
|
128
|
-
if node.class.method_defined? :
|
129
|
-
node.
|
130
|
-
if child_node.class.method_defined? :parent and !child_node.parent
|
131
|
-
child_node.parent = node
|
132
|
-
end
|
133
|
-
end
|
127
|
+
def attach_parent(node)
|
128
|
+
if node.class.method_defined? :attach_parent_to_children
|
129
|
+
node.attach_parent_to_children
|
134
130
|
end
|
135
131
|
end
|
136
132
|
|
@@ -1,16 +1,21 @@
|
|
1
1
|
module Expressir
|
2
2
|
module Model
|
3
3
|
class ModelElement
|
4
|
-
CLASS_KEY = '_class'
|
4
|
+
CLASS_KEY = '_class'
|
5
|
+
SOURCE_KEY = 'source'
|
5
6
|
|
6
7
|
def to_hash(options = {})
|
7
8
|
skip_empty = options[:skip_empty]
|
9
|
+
formatter = options[:formatter]
|
8
10
|
|
9
|
-
|
11
|
+
hash = {}
|
12
|
+
hash[CLASS_KEY] = self.class.name
|
13
|
+
|
14
|
+
instance_variables.select{|x| x != :@parent}.each_with_object(hash) do |variable, result|
|
10
15
|
key = variable.to_s.sub(/^@/, '')
|
11
16
|
value = instance_variable_get(variable)
|
12
17
|
|
13
|
-
# skip
|
18
|
+
# skip empty values (nil, empty array)
|
14
19
|
if !skip_empty or !(value.nil? or (value.is_a? Array and value.count == 0))
|
15
20
|
result[key] = if value.is_a? Array
|
16
21
|
value.map do |value|
|
@@ -27,6 +32,12 @@ module Expressir
|
|
27
32
|
end
|
28
33
|
end
|
29
34
|
end
|
35
|
+
|
36
|
+
if formatter
|
37
|
+
hash[SOURCE_KEY] = formatter.format(self)
|
38
|
+
end
|
39
|
+
|
40
|
+
hash
|
30
41
|
end
|
31
42
|
|
32
43
|
def self.from_hash(hash)
|
@@ -51,13 +62,8 @@ module Expressir
|
|
51
62
|
|
52
63
|
node = Object.const_get(node_class).new(node_options)
|
53
64
|
|
54
|
-
|
55
|
-
|
56
|
-
node.children.each do |child_node|
|
57
|
-
if child_node.class.method_defined? :parent and !child_node.parent
|
58
|
-
child_node.parent = node
|
59
|
-
end
|
60
|
-
end
|
65
|
+
if node.class.method_defined? :attach_parent_to_children
|
66
|
+
node.attach_parent_to_children
|
61
67
|
end
|
62
68
|
|
63
69
|
node
|
@@ -55,6 +55,14 @@ module Expressir
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
+
def attach_parent_to_children
|
59
|
+
children.each do |child_node|
|
60
|
+
if child_node.class.method_defined? :parent and !child_node.parent
|
61
|
+
child_node.parent = self
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
58
66
|
def children
|
59
67
|
raise 'Not implemented'
|
60
68
|
end
|
data/lib/expressir/version.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
require "expressir/express_exp/parser"
|
3
|
+
require "expressir/express_exp/formatter"
|
3
4
|
|
4
5
|
RSpec.describe Expressir::Model::ModelElement do
|
5
6
|
describe ".from_hash" do
|
6
|
-
it "parses an object from hash" do
|
7
|
+
it "parses an object from a hash" do
|
7
8
|
input = {
|
8
9
|
"_class" => "Expressir::Model::Repository",
|
9
10
|
"schemas" => [{
|
@@ -21,17 +22,17 @@ RSpec.describe Expressir::Model::ModelElement do
|
|
21
22
|
expect(repo).to be_instance_of(Expressir::Model::Repository)
|
22
23
|
expect(repo.schemas).to be_instance_of(Array)
|
23
24
|
expect(repo.schemas.count).to eq(1)
|
24
|
-
expect(repo.schemas
|
25
|
-
expect(repo.schemas
|
26
|
-
expect(repo.schemas
|
27
|
-
expect(repo.schemas
|
28
|
-
expect(repo.schemas
|
29
|
-
expect(repo.schemas
|
25
|
+
expect(repo.schemas.first).to be_instance_of(Expressir::Model::Schema)
|
26
|
+
expect(repo.schemas.first.id).to eq("simple_schema")
|
27
|
+
expect(repo.schemas.first.entities).to be_instance_of(Array)
|
28
|
+
expect(repo.schemas.first.entities.count).to eq(1)
|
29
|
+
expect(repo.schemas.first.entities.first).to be_instance_of(Expressir::Model::Entity)
|
30
|
+
expect(repo.schemas.first.entities.first.id).to eq("empty_entity")
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
33
34
|
describe ".to_hash" do
|
34
|
-
it "exports an object to hash" do
|
35
|
+
it "exports an object to a hash" do
|
35
36
|
repo = Expressir::ExpressExp::Parser.from_exp(sample_file)
|
36
37
|
|
37
38
|
result = repo.to_hash
|
@@ -40,14 +41,31 @@ RSpec.describe Expressir::Model::ModelElement do
|
|
40
41
|
expect(result["_class"]).to eq("Expressir::Model::Repository")
|
41
42
|
expect(result["schemas"]).to be_instance_of(Array)
|
42
43
|
expect(result["schemas"].count).to eq(1)
|
43
|
-
expect(result["schemas"]
|
44
|
-
expect(result["schemas"][
|
45
|
-
expect(result["schemas"][
|
46
|
-
expect(result["schemas"][
|
47
|
-
expect(result["schemas"][
|
48
|
-
expect(result["schemas"][
|
49
|
-
expect(result["schemas"][
|
50
|
-
expect(result["schemas"][
|
44
|
+
expect(result["schemas"].first).to be_instance_of(Hash)
|
45
|
+
expect(result["schemas"].first["_class"]).to eq("Expressir::Model::Schema")
|
46
|
+
expect(result["schemas"].first["id"]).to eq("simple_schema")
|
47
|
+
expect(result["schemas"].first["entities"]).to be_instance_of(Array)
|
48
|
+
expect(result["schemas"].first["entities"].count).to eq(1)
|
49
|
+
expect(result["schemas"].first["entities"].first).to be_instance_of(Hash)
|
50
|
+
expect(result["schemas"].first["entities"].first["_class"]).to eq("Expressir::Model::Entity")
|
51
|
+
expect(result["schemas"].first["entities"].first["id"]).to eq("empty_entity")
|
52
|
+
end
|
53
|
+
|
54
|
+
it "exports an object to a hash with a custom formatter" do
|
55
|
+
repo = Expressir::ExpressExp::Parser.from_exp(sample_file)
|
56
|
+
|
57
|
+
class CustomFormatter < Expressir::ExpressExp::Formatter
|
58
|
+
def format_schema(node)
|
59
|
+
"Oook."
|
60
|
+
end
|
61
|
+
end
|
62
|
+
result = repo.to_hash({ formatter: CustomFormatter })
|
63
|
+
|
64
|
+
expect(result).to be_instance_of(Hash)
|
65
|
+
expect(result["_class"]).to eq("Expressir::Model::Repository")
|
66
|
+
expect(result["schemas"]).to be_instance_of(Array)
|
67
|
+
expect(result["schemas"].count).to eq(1)
|
68
|
+
expect(result["schemas"].first["source"]).to eq("Oook.")
|
51
69
|
end
|
52
70
|
end
|
53
71
|
|
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.
|
4
|
+
version: 0.2.11
|
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-02-
|
11
|
+
date: 2021-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|