expressir 1.3.3 → 1.4.0

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: f977bc7a798a2d046e6c5add063c3b80eda8f0441eaac5bc06e7eb493d78b225
4
- data.tar.gz: f4794f33744e62fb5eb05e1dcb557f97d21afc6c9e34e6fe4af479e8f0a60d0e
3
+ metadata.gz: c715677941cba222f7a4021ab2e392272e39646afb83c739350a845e0d7f0918
4
+ data.tar.gz: eb8de33aa98749b1518305b4b34c0f49a685829739ddc79f784b0b2d4d4a68a8
5
5
  SHA512:
6
- metadata.gz: 4bd6f5a8630de8670088b3e263e6523143241954f10abaa472b3f7421da9b31f8c5f3f77d9f21de66c10bb753da7dcf8c43b68d69bee8e1a24fe41039378a08e
7
- data.tar.gz: 9884812d1d614105b3b82c07702a659ce28d3b94a7f4657d1fcc06e4695ef4aa3d6b176624627f82fa179d5735de83d8eba80cd1bcf8a2735c6ed5d32b93cdd9
6
+ metadata.gz: '0349a84ac72ce995d67070fd27a9f2b543ca0b4f6e10ae5e4f47606287575261b3e76540b55b3517a6273882b6b1a2f94ee2771a9382e7e49c3b584b0cd56146'
7
+ data.tar.gz: 592ec3ace51fd074f297fd8381ccf9fb0fbaf1d0fa6dfbf7327c28778ef92b07222ae70b93b8ca2e64504815ebdb06d66cf68e32c656b8c5611bb471aa81d9bb
data/README.adoc CHANGED
@@ -38,13 +38,22 @@ instructions.
38
38
 
39
39
  [source, sh]
40
40
  ----
41
- ./exe/expressir
41
+ $ expressir
42
42
 
43
43
  Commands:
44
+ expressir format PATH # pretty print EXPRESS schema located at PATH
44
45
  expressir help [COMMAND] # Describe available commands or one specific command
45
46
  expressir version # The Expressir Version
46
47
  ----
47
48
 
49
+ === Pretty print
50
+
51
+ [source, sh]
52
+ ----
53
+ expressir format schemas/resources/action_schema/action_schema.exp
54
+ ----
55
+
56
+
48
57
  == Development
49
58
 
50
59
  We are following Sandi Metz's Rules for this gem, you can read
@@ -66,22 +75,31 @@ Setup your environment.
66
75
  [source, sh]
67
76
  ----
68
77
  bin/setup
78
+ git submodule update --init
79
+ bundle exec rake generate
80
+ bundle exec rake compile
69
81
  ----
70
82
 
71
83
  Run the test suite
72
84
 
73
85
  [source, sh]
74
86
  ----
75
- bin/rspec
87
+ bundle exec rake
76
88
  ----
77
89
 
78
90
  === Grammar updates
79
- EXPRESS grammar is lined as git submodule to ext/express-grammar
80
- Shoudl you update it, run ```rake generate```. This command will generate source code for updated native extension using antlr4-native gem.
81
- Please note that we create several classes on top of antlr4-native output so using embedded rake task is a real requirement.
82
91
 
83
- When new extension is gnerated and tested plase check in updated C++ files to git (```rake generate``` is NOT a CI step,
84
- extension source files are pulled from the repo).
92
+ THe EXPRESS grammar is lined as Git submodule at `ext/express-grammar`.
93
+
94
+ Should you update it, please run `rake generate`. This command will generate
95
+ source code for updated native extension using the `antlr4-native` gem. Please
96
+ note that we create several classes on top of `antlr4-native` output so using
97
+ embedded rake task is a real requirement.
98
+
99
+ When a new extension is generated and tested, please check in updated C++ files
100
+ to git (`rake generate` is NOT a CI step, extension source files are pulled from
101
+ the repo).
102
+
85
103
 
86
104
  == Installation
87
105
 
data/exe/format CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "yaml"
4
- require "expressir/express/parser"
4
+ require "expressir"
5
5
  require "expressir/express/formatter"
6
6
  require "expressir/express/schema_head_formatter"
7
7
  require "expressir/express/hyperlink_formatter"
@@ -9,10 +9,6 @@ require "expressir/express/hyperlink_formatter"
9
9
  exp_files = ARGV
10
10
 
11
11
  repository = Expressir::Express::Parser.from_files(exp_files)
12
- formatter = Class.new(Expressir::Express::Formatter) do
13
- include Expressir::Express::SchemaHeadFormatter
14
- include Expressir::Express::HyperlinkFormatter
12
+ repository.schemas.each do |schema|
13
+ puts schema.to_s(no_remarks: true)
15
14
  end
16
- result = repository.to_hash(formatter: formatter, skip_empty: true)
17
-
18
- puts YAML.dump(result)
data/exe/format-test CHANGED
@@ -75,7 +75,7 @@ formatter = Class.new(Expressir::Express::Formatter) do
75
75
  include Expressir::Express::SchemaHeadFormatter
76
76
  include Expressir::Express::HyperlinkFormatter
77
77
  end
78
- result = repository.to_hash(formatter: formatter, skip_empty: true)
78
+ result = repository.to_hash(formatter: formatter)
79
79
  puts "Repository.to_hash time: #{(Time.now - start).round(2)}s"
80
80
 
81
81
  # puts YAML.dump(result)
data/lib/expressir/cli.rb CHANGED
@@ -1,21 +1,19 @@
1
1
  require "thor"
2
- require "expressir/cli/ui"
3
2
 
4
3
  module Expressir
5
- module Cli
6
- def self.ui
7
- Expressir::Cli::UI
8
- end
9
-
10
- def self.start(args)
11
- Base.start(args)
4
+ class Cli < Thor
5
+ desc "format PATH", "pretty print EXPRESS schema located at PATH"
6
+ def format(path)
7
+ repository = Expressir::Express::Parser.from_file(path)
8
+ repository.schemas.each do |schema|
9
+ puts "\n(* Expressir formatted schema: #{schema.id} *)\n"
10
+ puts schema.to_s(no_remarks: true)
11
+ end
12
12
  end
13
13
 
14
- class Base < Thor
15
- desc "version", "The Expressir Version"
16
- def version
17
- Cli.ui.say("Version #{Expressir::VERSION}")
18
- end
14
+ desc "version", "Expressir Version"
15
+ def version
16
+ say(Expressir::VERSION)
19
17
  end
20
18
  end
21
19
  end
@@ -104,20 +104,21 @@ module Expressir
104
104
  empty = value.nil? || (value.is_a?(Array) && value.count == 0)
105
105
 
106
106
  # skip empty values
107
- if !empty or include_empty
108
- hash[variable.to_s] = if value.is_a? Array
109
- value.map do |value|
110
- if value.is_a? ModelElement
111
- value.to_hash(root_path: root_path, formatter: formatter, include_empty: include_empty)
112
- else
113
- value
114
- end
107
+ next unless !empty or include_empty
108
+
109
+ hash[variable.to_s] = case value
110
+ when Array
111
+ value.map do |value|
112
+ if value.is_a? ModelElement
113
+ value.to_hash(root_path: root_path, formatter: formatter, include_empty: include_empty)
114
+ else
115
+ value
115
116
  end
116
- elsif value.is_a? ModelElement
117
- value.to_hash(root_path: root_path, formatter: formatter, include_empty: include_empty)
118
- else
119
- value
120
117
  end
118
+ when ModelElement
119
+ value.to_hash(root_path: root_path, formatter: formatter, include_empty: include_empty)
120
+ else
121
+ value
121
122
  end
122
123
  end
123
124
 
@@ -132,6 +133,19 @@ module Expressir
132
133
  hash
133
134
  end
134
135
 
136
+ def to_s
137
+ to_s(no_remarks: false, formatter: nil)
138
+ end
139
+
140
+ def to_s(no_remarks: false, formatter: nil)
141
+ formatter ||= Class.new(Expressir::Express::Formatter) do
142
+ if no_remarks
143
+ def format_remarks(node); []; end
144
+ end
145
+ end
146
+ formatter.format(self)
147
+ end
148
+
135
149
  # @param [Hash] hash
136
150
  # @param [String] root_path
137
151
  # @return [ModelElement]
@@ -142,7 +156,8 @@ module Expressir
142
156
  node_class.model_attrs.each do |variable|
143
157
  value = hash[variable.to_s]
144
158
 
145
- node_options[variable] = if value.is_a? Array
159
+ node_options[variable] = case value
160
+ when Array
146
161
  value.map do |value|
147
162
  if value.is_a? Hash
148
163
  self.from_hash(value, root_path: root_path)
@@ -150,7 +165,7 @@ module Expressir
150
165
  value
151
166
  end
152
167
  end
153
- elsif value.is_a? Hash
168
+ when Hash
154
169
  self.from_hash(value, root_path: root_path)
155
170
  else
156
171
  value
@@ -191,13 +206,14 @@ module Expressir
191
206
  self.class.model_attrs.each do |variable|
192
207
  value = self.send(variable)
193
208
 
194
- if value.is_a? Array
209
+ case value
210
+ when Array
195
211
  value.each do |value|
196
212
  if value.is_a? ModelElement
197
213
  value.parent = self
198
214
  end
199
215
  end
200
- elsif value.is_a? ModelElement
216
+ when ModelElement
201
217
  value.parent = self
202
218
  end
203
219
  end
@@ -18,6 +18,7 @@ module Expressir
18
18
  *schemas
19
19
  ]
20
20
  end
21
+
21
22
  end
22
23
  end
23
24
  end
@@ -1,3 +1,3 @@
1
1
  module Expressir
2
- VERSION = "1.3.3".freeze
2
+ VERSION = "1.4.0".freeze
3
3
  end
data/lib/expressir.rb CHANGED
@@ -3,10 +3,6 @@ require "expressir/version"
3
3
  require "expressir/cli"
4
4
  require "expressir/config"
5
5
 
6
- Dir[File.join(__dir__, "expressir", "express", "*.rb")].sort.each do |fea|
7
- require fea
8
- end
9
-
10
6
  # ..........................................................
11
7
  # https://bugs.ruby-lang.org/issues/19319
12
8
  # The issue is that this bug is fixed for 3.1 and above,
@@ -30,10 +26,6 @@ end
30
26
  module Expressir
31
27
  class Error < StandardError; end
32
28
 
33
- def self.ui
34
- Expressir::Cli::UI
35
- end
36
-
37
29
  def self.root
38
30
  File.dirname(__dir__)
39
31
  end
@@ -42,3 +34,7 @@ module Expressir
42
34
  @root_path ||= Pathname.new(Expressir.root)
43
35
  end
44
36
  end
37
+
38
+ Dir[File.join(__dir__, "expressir", "express", "*.rb")].sort.each do |fea|
39
+ require fea
40
+ end
@@ -19,7 +19,7 @@ RSpec.describe "Expressir" do
19
19
  print "\n[#{example.description}] "
20
20
  command = %w(version)
21
21
  output = capture_stdout { Expressir::Cli.start(command) }
22
- expect(output).to include("Version #{Expressir::VERSION}")
22
+ expect(output).to include(Expressir::VERSION)
23
23
 
24
24
  # Validate Object Space
25
25
  GC.start
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: 1.3.3
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-04-18 00:00:00.000000000 Z
11
+ date: 2024-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rice
@@ -605,7 +605,6 @@ files:
605
605
  - ext/express_parser/extconf.rb
606
606
  - lib/expressir.rb
607
607
  - lib/expressir/cli.rb
608
- - lib/expressir/cli/ui.rb
609
608
  - lib/expressir/config.rb
610
609
  - lib/expressir/express/cache.rb
611
610
  - lib/expressir/express/formatter.rb
@@ -1,36 +0,0 @@
1
- require "thor"
2
-
3
- module Expressir
4
- module Cli
5
- class UI < Thor
6
- def self.ask(message)
7
- new.ask(message)
8
- end
9
-
10
- def self.say(message)
11
- new.say(message)
12
- end
13
-
14
- def self.error(message)
15
- if log_types.include?("error")
16
- new.error(message)
17
- end
18
- end
19
-
20
- def self.info(message)
21
- if log_types.include?("info")
22
- new.say(message)
23
- end
24
- end
25
-
26
- def self.run(command)
27
- require "open3"
28
- Open3.capture3(command)
29
- end
30
-
31
- def self.log_types
32
- Expressir.configuration.logs.map(&:to_s) || []
33
- end
34
- end
35
- end
36
- end