script_core 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +131 -36
  3. data/Gemfile +2 -2
  4. data/lib/script_core/executable.rb +1 -1
  5. data/lib/script_core/message_processor.rb +48 -48
  6. data/lib/script_core/version.rb +1 -1
  7. data/lib/tasks/script_core.rake +47 -31
  8. data/spec/dummy/app/controllers/application_controller.rb +11 -11
  9. data/spec/dummy/app/controllers/fields/application_controller.rb +14 -14
  10. data/spec/dummy/app/controllers/fields/choices_controller.rb +8 -10
  11. data/spec/dummy/app/controllers/fields/options_controller.rb +6 -6
  12. data/spec/dummy/app/controllers/fields/validations_controller.rb +6 -6
  13. data/spec/dummy/app/controllers/forms/application_controller.rb +4 -4
  14. data/spec/dummy/app/controllers/forms/fields_controller.rb +8 -8
  15. data/spec/dummy/app/controllers/forms/formulas/application_controller.rb +7 -7
  16. data/spec/dummy/app/controllers/forms/formulas/playgrounds_controller.rb +6 -6
  17. data/spec/dummy/app/controllers/forms/formulas_controller.rb +8 -8
  18. data/spec/dummy/app/controllers/forms_controller.rb +8 -8
  19. data/spec/dummy/app/controllers/nested_forms/application_controller.rb +4 -4
  20. data/spec/dummy/app/controllers/nested_forms/fields_controller.rb +8 -8
  21. data/spec/dummy/app/controllers/playgrounds_controller.rb +3 -3
  22. data/spec/dummy/app/controllers/time_zones_controller.rb +1 -3
  23. data/spec/dummy/app/lib/script_engine.rb +1 -1
  24. data/spec/dummy/app/models/concerns/fields/validations/exclusion.rb +1 -1
  25. data/spec/dummy/app/models/concerns/fields/validations/format.rb +1 -1
  26. data/spec/dummy/app/models/concerns/fields/validations/inclusion.rb +1 -1
  27. data/spec/dummy/app/models/concerns/fields/validations/length.rb +1 -1
  28. data/spec/dummy/app/models/field.rb +25 -25
  29. data/spec/dummy/app/models/field_options.rb +55 -61
  30. data/spec/dummy/app/models/fields/date_field.rb +5 -5
  31. data/spec/dummy/app/models/fields/datetime_field.rb +5 -5
  32. data/spec/dummy/app/models/fields/integer_field.rb +4 -4
  33. data/spec/dummy/app/models/fields/multiple_nested_form_field.rb +2 -4
  34. data/spec/dummy/app/models/fields/multiple_select_field.rb +6 -8
  35. data/spec/dummy/app/models/fields/nested_form_field.rb +2 -4
  36. data/spec/dummy/app/models/fields/options/date_field.rb +5 -5
  37. data/spec/dummy/app/models/fields/options/datetime_field.rb +5 -5
  38. data/spec/dummy/app/models/fields/select_field.rb +5 -5
  39. data/spec/dummy/app/{decorators → overrides}/.keep +0 -0
  40. data/spec/dummy/app/presenters/concerns/fields/presenter_for_number_field.rb +1 -1
  41. data/spec/dummy/app/views/_form_core/fields/_multiple_nested_form_field.html.erb +2 -2
  42. data/spec/dummy/app/views/_form_core/fields/_multiple_select_field.html.erb +10 -2
  43. data/spec/dummy/app/views/_form_core/fields/_nested_form.html.erb +3 -1
  44. data/spec/dummy/app/views/_form_core/fields/_nested_form_field.html.erb +2 -2
  45. data/spec/dummy/app/views/_form_core/fields/_select_field.html.erb +9 -2
  46. data/spec/dummy/config/application.rb +8 -1
  47. data/spec/dummy/db/migrate/20180916202025_create_forms.form_core.rb +1 -1
  48. data/spec/dummy/lib/monkey_patches/big_decimal.rb +4 -4
  49. data/spec/dummy/lib/monkey_patches/date.rb +4 -4
  50. data/spec/dummy/lib/monkey_patches/time.rb +4 -4
  51. data/spec/dummy/test/application_system_test_case.rb +7 -0
  52. data/spec/script_core/message_processor_spec.rb +4 -4
  53. data/spec/script_core/service_process_spec.rb +4 -4
  54. data/spec/script_core/stat_spec.rb +2 -2
  55. data/spec/script_core_spec.rb +10 -10
  56. metadata +4 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ede1652ae58420a03a24ee7b0a0336663609539818ac5e78eefd1b44f559e79f
4
- data.tar.gz: a89ceb1cfd340b55c57a031520f48f45e97f66d9177ca4f75800c5b23e9e3398
3
+ metadata.gz: 7d22fc6516b63706a508249edf80db433c0867bdce486c67f37f7a6e7554aee3
4
+ data.tar.gz: 38fa2692788d8d8da328b5658ed4a9b1229f7249658b414ed1737dd57f3e3af8
5
5
  SHA512:
6
- metadata.gz: e4c1ab03a8ad1d0ac10c8910a9946093f086b6df33a3e41071c6d5c0ec0dc0c8446c1724ce9ab0f6525865183b93b9c471538d33fe283957f3f126984bd1e9d3
7
- data.tar.gz: 07df21c99ee18cba6f3accffd8d9cfca55e203d7f0be33bdef56af267a8e1fbe3e091df7272db421f35b7879dbd2469c4a3cb89eb07307f1573a6f3e74ce054e
6
+ metadata.gz: e9ffbfa5ee5bfba957357126f5e07f4979fdde23c42e84371cd5ed346cdcc8da367559d876a1813cf95c21a289c390d0c0429ce904bbc2fc889e81f4ec106869
7
+ data.tar.gz: 57171be0b55234ccc9eafad9c019a158d8d7d5626619d5cb5f504e87139b2afb60c47345056b25876211a09f7163f09cdede9b12c99048b987f2b223a2c6f1a9
data/.rubocop.yml CHANGED
@@ -13,13 +13,45 @@ AllCops:
13
13
  - spec/dummy/db/schema.rb
14
14
  - spec/dummy/bin/**/*
15
15
 
16
+ Rails:
17
+ Enabled: true
18
+
16
19
  Metrics/LineLength:
17
20
  Max: 150
18
21
 
19
- # frozen_string_literal: true
20
- Style/FrozenStringLiteralComment:
21
- Enabled: true
22
- EnforcedStyle: when_needed
22
+ Metrics/MethodLength:
23
+ Max: 100
24
+
25
+ Metrics/BlockLength:
26
+ Max: 50
27
+
28
+ Metrics/ClassLength:
29
+ Enabled: false
30
+
31
+ Style/GuardClause:
32
+ Enabled: false
33
+
34
+ Style/Documentation:
35
+ Enabled: false
36
+
37
+ Style/ClassAndModuleChildren:
38
+ Enabled: false
39
+
40
+ Naming/AccessorMethodName:
41
+ Enabled: false
42
+
43
+ Naming/MemoizedInstanceVariableName:
44
+ Enabled: false
45
+
46
+ # Prefer assert_not over assert !
47
+ Rails/AssertNot:
48
+ Include:
49
+ - 'test/**/*'
50
+
51
+ # Prefer assert_not_x over refute_x
52
+ Rails/RefuteMethods:
53
+ Include:
54
+ - 'test/**/*'
23
55
 
24
56
  # Prefer &&/|| over and/or.
25
57
  Style/AndOr:
@@ -29,6 +61,7 @@ Style/AndOr:
29
61
  # method call.
30
62
  Style/BracesAroundHashParameters:
31
63
  Enabled: true
64
+ EnforcedStyle: context_dependent
32
65
 
33
66
  # Align `when` with `case`.
34
67
  Layout/CaseIndentation:
@@ -38,8 +71,20 @@ Layout/CaseIndentation:
38
71
  Layout/CommentIndentation:
39
72
  Enabled: true
40
73
 
41
- # No extra empty lines.
42
- Layout/EmptyLines:
74
+ Layout/ElseAlignment:
75
+ Enabled: true
76
+
77
+ # Align `end` with the matching keyword or starting expression except for
78
+ # assignments, where it should be aligned with the LHS.
79
+ Layout/EndAlignment:
80
+ Enabled: true
81
+ EnforcedStyleAlignWith: variable
82
+ AutoCorrect: true
83
+
84
+ Layout/EmptyLineAfterMagicComment:
85
+ Enabled: true
86
+
87
+ Layout/EmptyLinesAroundBlockBody:
43
88
  Enabled: true
44
89
 
45
90
  # In a regular class definition, no empty lines around the body.
@@ -54,7 +99,10 @@ Layout/EmptyLinesAroundMethodBody:
54
99
  Layout/EmptyLinesAroundModuleBody:
55
100
  Enabled: true
56
101
 
57
- # Use Ruby >= 1.9 syntax for hashes. Prefer {a: :b} over { :a => :b }.
102
+ Layout/IndentFirstArgument:
103
+ Enabled: true
104
+
105
+ # Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
58
106
  Style/HashSyntax:
59
107
  Enabled: true
60
108
 
@@ -62,18 +110,24 @@ Style/HashSyntax:
62
110
  # extra level of indentation.
63
111
  Layout/IndentationConsistency:
64
112
  Enabled: true
65
- EnforcedStyle: normal
113
+ EnforcedStyle: rails
66
114
 
67
115
  # Two spaces, no tabs (for indentation).
68
116
  Layout/IndentationWidth:
69
117
  Enabled: true
70
118
 
119
+ Layout/LeadingCommentSpace:
120
+ Enabled: true
121
+
71
122
  Layout/SpaceAfterColon:
72
123
  Enabled: true
73
124
 
74
125
  Layout/SpaceAfterComma:
75
126
  Enabled: true
76
127
 
128
+ Layout/SpaceAfterSemicolon:
129
+ Enabled: true
130
+
77
131
  Layout/SpaceAroundEqualsInParameterDefault:
78
132
  Enabled: true
79
133
 
@@ -83,13 +137,26 @@ Layout/SpaceAroundKeyword:
83
137
  Layout/SpaceAroundOperators:
84
138
  Enabled: true
85
139
 
140
+ Layout/SpaceBeforeComma:
141
+ Enabled: true
142
+
86
143
  Layout/SpaceBeforeFirstArg:
87
144
  Enabled: true
88
145
 
146
+ Style/DefWithParentheses:
147
+ Enabled: true
148
+
89
149
  # Defining a method with parameters needs parentheses.
90
150
  Style/MethodDefParentheses:
91
151
  Enabled: true
92
152
 
153
+ Style/FrozenStringLiteralComment:
154
+ Enabled: true
155
+ EnforcedStyle: always
156
+
157
+ Style/RedundantFreeze:
158
+ Enabled: true
159
+
93
160
  # Use `foo {}` not `foo{}`.
94
161
  Layout/SpaceBeforeBlockBraces:
95
162
  Enabled: true
@@ -97,10 +164,11 @@ Layout/SpaceBeforeBlockBraces:
97
164
  # Use `foo { bar }` not `foo {bar}`.
98
165
  Layout/SpaceInsideBlockBraces:
99
166
  Enabled: true
167
+ EnforcedStyleForEmptyBraces: space
100
168
 
101
- # Use `{a: 1}` not `{ a:1 }`.
169
+ # Use `{ a: 1 }` not `{a:1}`.
102
170
  Layout/SpaceInsideHashLiteralBraces:
103
- Enabled: false
171
+ Enabled: true
104
172
 
105
173
  Layout/SpaceInsideParens:
106
174
  Enabled: true
@@ -126,45 +194,72 @@ Layout/TrailingWhitespace:
126
194
  Style/UnneededPercentQ:
127
195
  Enabled: true
128
196
 
129
- # Align `end` with the matching keyword or starting expression except for
130
- # assignments, where it should be aligned with the LHS.
131
- Layout/EndAlignment:
197
+ Lint/AmbiguousOperator:
198
+ Enabled: true
199
+
200
+ Lint/AmbiguousRegexpLiteral:
201
+ Enabled: true
202
+
203
+ Lint/ErbNewArguments:
132
204
  Enabled: true
133
- EnforcedStyleAlignWith: variable
134
205
 
135
206
  # Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
136
207
  Lint/RequireParentheses:
137
208
  Enabled: true
138
209
 
139
- Style/Documentation:
140
- Enabled: false
210
+ Lint/ShadowingOuterLocalVariable:
211
+ Enabled: true
141
212
 
142
- Metrics/MethodLength:
143
- Enabled: false
213
+ Lint/StringConversionInInterpolation:
214
+ Enabled: true
144
215
 
145
- Metrics/AbcSize:
146
- Enabled: false
216
+ Lint/UriEscapeUnescape:
217
+ Enabled: true
147
218
 
148
- Metrics/ParameterLists:
149
- Enabled: false
219
+ Lint/UselessAssignment:
220
+ Enabled: true
150
221
 
151
- Metrics/BlockLength:
152
- Enabled: false
222
+ Lint/DeprecatedClassMethods:
223
+ Enabled: true
153
224
 
154
- Lint/HandleExceptions:
155
- Enabled: false
225
+ Style/ParenthesesAroundCondition:
226
+ Enabled: true
156
227
 
157
- Metrics/ClassLength:
158
- Enabled: false
228
+ Style/RedundantBegin:
229
+ Enabled: true
159
230
 
160
- Layout/EmptyLinesAroundArguments:
161
- Enabled: false
231
+ Style/RedundantReturn:
232
+ Enabled: true
233
+ AllowMultipleReturnValues: true
162
234
 
163
- Style/ClassAndModuleChildren:
164
- Enabled: false
235
+ Style/Semicolon:
236
+ Enabled: true
237
+ AllowAsExpressionSeparator: true
165
238
 
166
- Naming/UncommunicativeMethodParamName:
167
- Enabled: false
239
+ # Prefer Foo.method over Foo::method
240
+ Style/ColonMethodCall:
241
+ Enabled: true
168
242
 
169
- Style/IfUnlessModifier:
170
- Enabled: false
243
+ Style/TrivialAccessors:
244
+ Enabled: true
245
+
246
+ Performance/FlatMap:
247
+ Enabled: true
248
+
249
+ Performance/RedundantMerge:
250
+ Enabled: true
251
+
252
+ Performance/StartWith:
253
+ Enabled: true
254
+
255
+ Performance/EndWith:
256
+ Enabled: true
257
+
258
+ Performance/RegexpMatch:
259
+ Enabled: true
260
+
261
+ Performance/ReverseEach:
262
+ Enabled: true
263
+
264
+ Performance/UnfreezeString:
265
+ Enabled: true
data/Gemfile CHANGED
@@ -6,7 +6,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
6
6
  gemspec
7
7
 
8
8
  # Dummy app
9
- gem "rails", "~> 6.0.0.beta3"
9
+ gem "rails", "~> 6.0.0.rc1"
10
10
  gem "sqlite3"
11
11
 
12
12
  # Use Puma as the app server
@@ -16,7 +16,7 @@ gem "pry-rails"
16
16
 
17
17
  gem "listen", ">= 3.0.5", "< 3.2"
18
18
  # Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
19
- gem "web-console"
19
+ gem "web-console", group: :development
20
20
  # Call "byebug" anywhere in the code to stop execution and get a debugger console
21
21
  gem "pry-byebug"
22
22
 
@@ -17,7 +17,7 @@ def run(input: {}, sources:, instructions: nil,
17
17
  environment_variables: {})
18
18
  packer = ScriptCore::Protocol.packer_factory.packer
19
19
 
20
- payload = {input: input, sources: sources}
20
+ payload = { input: input, sources: sources }
21
21
  payload[:library] = instructions if instructions
22
22
  encoded = packer.pack(payload)
23
23
 
@@ -71,61 +71,61 @@ def to_result
71
71
 
72
72
  private
73
73
 
74
- def read(raw_message)
75
- type, data = raw_message
76
- case type
77
- when :output then read_output(data)
78
- when :error then read_error(data)
79
- when :measurement then read_measurement(data)
80
- when :stat then read_stat(data)
74
+ def read(raw_message)
75
+ type, data = raw_message
76
+ case type
77
+ when :output then read_output(data)
78
+ when :error then read_error(data)
79
+ when :measurement then read_measurement(data)
80
+ when :stat then read_stat(data)
81
+ end
81
82
  end
82
- end
83
83
 
84
- def read_output(data)
85
- @output = data[:extracted]
86
- @stdout = data[:stdout]
87
- end
84
+ def read_output(data)
85
+ @output = data[:extracted]
86
+ @stdout = data[:stdout]
87
+ end
88
88
 
89
- def read_error(data)
90
- @errors <<
91
- case data[:__type]
92
- when :runtime
93
- EngineRuntimeError.new(
94
- data[:message],
95
- guest_backtrace: data[:backtrace]
96
- )
97
- when :syntax
98
- EngineSyntaxError.new(
99
- data[:message],
100
- filename: data[:filename],
101
- line_number: data[:line_number],
102
- column: data[:column]
103
- )
104
- when :unknown_type
105
- EngineUnknownTypeError.new(type: data[:type])
106
- when :unknown_ext
107
- EngineUnknownExtError.new(type: data[:type])
89
+ def read_error(data)
90
+ @errors <<
91
+ case data[:__type]
92
+ when :runtime
93
+ EngineRuntimeError.new(
94
+ data[:message],
95
+ guest_backtrace: data[:backtrace]
96
+ )
97
+ when :syntax
98
+ EngineSyntaxError.new(
99
+ data[:message],
100
+ filename: data[:filename],
101
+ line_number: data[:line_number],
102
+ column: data[:column]
103
+ )
104
+ when :unknown_type
105
+ EngineUnknownTypeError.new(type: data[:type])
106
+ when :unknown_ext
107
+ EngineUnknownExtError.new(type: data[:type])
108
+ else
109
+ EngineInternalError.new("unknown error: #{data}")
110
+ end
111
+ end
112
+
113
+ def read_measurement(data)
114
+ name, microseconds = *data
115
+ if @measurements.key?(name)
116
+ @measurements[name] += microseconds
108
117
  else
109
- EngineInternalError.new("unknown error: #{data}")
118
+ @measurements[name] = microseconds
110
119
  end
111
- end
112
-
113
- def read_measurement(data)
114
- name, microseconds = *data
115
- if @measurements.key?(name)
116
- @measurements[name] += microseconds
117
- else
118
- @measurements[name] = microseconds
119
120
  end
120
- end
121
121
 
122
- def read_stat(data)
123
- unless @stat == ScriptCore::Stat::Null
124
- @errors << ScriptCore::DuplicateMessageError.new(
125
- "duplicate stat message"
126
- )
122
+ def read_stat(data)
123
+ unless @stat == ScriptCore::Stat::Null
124
+ @errors << ScriptCore::DuplicateMessageError.new(
125
+ "duplicate stat message"
126
+ )
127
+ end
128
+ @stat = ScriptCore::Stat.new(data)
127
129
  end
128
- @stat = ScriptCore::Stat.new(data)
129
- end
130
130
  end
131
131
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ScriptCore
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
@@ -8,7 +8,7 @@
8
8
  namespace :engine do
9
9
  desc "Create a skeletal engine that can be customize at the path you specify"
10
10
  task :new do
11
- ARGV.each { |a| task(a.to_sym) {} }
11
+ ARGV.each { |a| task(a.to_sym) { } }
12
12
 
13
13
  name = ARGV[1] || DEFAULT_ENGINE_NAME
14
14
  unless /\A[a-z_]+\Z/.match?(name)
@@ -27,18 +27,24 @@
27
27
 
28
28
  desc "Build engine executables"
29
29
  task :build do
30
- ARGV.each { |a| task(a.to_sym) {} }
30
+ ARGV.each { |a| task(a.to_sym) { } }
31
+
32
+ path = Pathname.new(ENV["ENGINE_PATH"]).realpath rescue nil if ENV["ENGINE_PATH"].present?
33
+ engine_root =
34
+ if path
35
+ path
36
+ else
37
+ name = ARGV[1] || DEFAULT_ENGINE_NAME
38
+ unless /\A[a-z_]+\Z/.match?(name)
39
+ puts "Must provide a valid engine name."
40
+ exit 1
41
+ end
42
+ Rails.root.join(name)
43
+ end
31
44
 
32
- name = ARGV[1] || DEFAULT_ENGINE_NAME
33
- unless /\A[a-z_]+\Z/.match?(name)
34
- puts "Must provide a valid engine name."
35
- exit 1
36
- end
37
-
38
- engine_root = Rails.root.join(name)
39
45
  unless Dir.exist?(engine_root)
40
46
  puts "Engine home `#{engine_root}` doesn't exists."
41
- puts "You should run `rake script_core:engine:new #{name}` to create it first."
47
+ puts "You should run `rake script_core:engine:new` to create it first."
42
48
  exit 1
43
49
  end
44
50
 
@@ -51,24 +57,30 @@
51
57
  end
52
58
 
53
59
  Dir.chdir(SCRIPT_CORE_ROOT.join("ext/enterprise_script_service")) do
54
- sh("#{env_vars} #{Rails.root.join('bin/bundle')} exec rake")
60
+ sh("#{env_vars} #{Rails.root.join('bin', 'bundle')} exec rake")
55
61
  end
56
62
  end
57
63
 
58
64
  desc "Compile engine lib"
59
65
  task :compile_lib do
60
- ARGV.each { |a| task(a.to_sym) {} }
61
-
62
- name = ARGV[1] || DEFAULT_ENGINE_NAME
63
- unless /\A[a-z_]+\Z/.match?(name)
64
- puts "Must provide a valid engine name."
65
- exit 1
66
- end
66
+ ARGV.each { |a| task(a.to_sym) { } }
67
+
68
+ path = Pathname.new(ENV["ENGINE_PATH"]).realpath rescue nil if ENV["ENGINE_PATH"].present?
69
+ engine_root =
70
+ if path
71
+ path
72
+ else
73
+ name = ARGV[1] || DEFAULT_ENGINE_NAME
74
+ unless /\A[a-z_]+\Z/.match?(name)
75
+ puts "Must provide a valid engine name."
76
+ exit 1
77
+ end
78
+ Rails.root.join(name)
79
+ end
67
80
 
68
- engine_root = Rails.root.join(name)
69
81
  unless Dir.exist?(engine_root)
70
82
  puts "Engine home `#{engine_root}` doesn't exists."
71
- puts "You should run `rake script_core:engine:new #{name}` to create it first."
83
+ puts "You should run `rake script_core:engine:new` to create it first."
72
84
  exit 1
73
85
  end
74
86
 
@@ -91,24 +103,28 @@
91
103
 
92
104
  desc "Clean engine compiled files"
93
105
  task :clean do
94
- ARGV.each { |a| task(a.to_sym) {} }
95
-
96
- name = ARGV[1] || DEFAULT_ENGINE_NAME
97
- unless /\A[a-z_]+\Z/.match?(name)
98
- puts "Must provide a valid engine name."
99
- exit 1
100
- end
106
+ ARGV.each { |a| task(a.to_sym) { } }
107
+
108
+ path = Pathname.new(ENV["ENGINE_PATH"]).realpath rescue nil if ENV["ENGINE_PATH"].present?
109
+ engine_root =
110
+ if path
111
+ path
112
+ else
113
+ name = ARGV[1] || DEFAULT_ENGINE_NAME
114
+ unless /\A[a-z_]+\Z/.match?(name)
115
+ puts "Must provide a valid engine name."
116
+ exit 1
117
+ end
118
+ Rails.root.join(name)
119
+ end
101
120
 
102
- engine_root = Rails.root.join(name)
103
121
  unless Dir.exist?(engine_root)
104
122
  puts "Engine home `#{engine_root}` doesn't exists."
105
123
  exit 1
106
124
  end
107
125
 
108
126
  bin_path = engine_root.join("bin")
109
- if Dir.exist?(bin_path)
110
- FileUtils.remove_dir engine_root.join("bin")
111
- end
127
+ FileUtils.remove_dir engine_root.join("bin") if Dir.exist?(bin_path)
112
128
  end
113
129
  end
114
130
  end