script_core 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -7,16 +7,16 @@ class ApplicationController < ActionController::Base
7
7
 
8
8
  private
9
9
 
10
- def set_time_zone(&block)
11
- Time.use_zone(current_time_zone, &block)
12
- end
10
+ def set_time_zone(&block)
11
+ Time.use_zone(current_time_zone, &block)
12
+ end
13
13
 
14
- def current_time_zone
15
- @current_time_zone ||=
16
- if session[:current_time_zone].present?
17
- ActiveSupport::TimeZone[session[:current_time_zone]] || ActiveSupport::TimeZone["UTC"]
18
- else
19
- ActiveSupport::TimeZone["UTC"]
20
- end
21
- end
14
+ def current_time_zone
15
+ @current_time_zone ||=
16
+ if session[:current_time_zone].present?
17
+ ActiveSupport::TimeZone[session[:current_time_zone]] || ActiveSupport::TimeZone["UTC"]
18
+ else
19
+ ActiveSupport::TimeZone["UTC"]
20
+ end
21
+ end
22
22
  end
@@ -5,21 +5,21 @@ class Fields::ApplicationController < ApplicationController
5
5
 
6
6
  protected
7
7
 
8
- # Use callbacks to share common setup or constraints between actions.
9
- def set_field
10
- @field = Field.find(params[:field_id])
11
- end
8
+ # Use callbacks to share common setup or constraints between actions.
9
+ def set_field
10
+ @field = Field.find(params[:field_id])
11
+ end
12
12
 
13
- def fields_url
14
- form = @field.form
13
+ def fields_url
14
+ form = @field.form
15
15
 
16
- case form
17
- when Form
18
- form_fields_url(form)
19
- when NestedForm
20
- nested_form_fields_url(form)
21
- else
22
- raise "Unknown form: #{form.class}"
16
+ case form
17
+ when Form
18
+ form_fields_url(form)
19
+ when NestedForm
20
+ nested_form_fields_url(form)
21
+ else
22
+ raise "Unknown form: #{form.class}"
23
+ end
23
24
  end
24
- end
25
25
  end
@@ -34,17 +34,15 @@ def destroy
34
34
 
35
35
  private
36
36
 
37
- def require_attach_choices!
38
- unless @field.attached_choices?
39
- redirect_to fields_url
37
+ def require_attach_choices!
38
+ redirect_to fields_url unless @field.attached_choices?
40
39
  end
41
- end
42
40
 
43
- def choice_params
44
- params.require(:choice).permit(:label)
45
- end
41
+ def choice_params
42
+ params.require(:choice).permit(:label)
43
+ end
46
44
 
47
- def set_choice
48
- @choice = @field.choices.find(params[:id])
49
- end
45
+ def set_choice
46
+ @choice = @field.choices.find(params[:id])
47
+ end
50
48
  end
@@ -16,11 +16,11 @@ def update
16
16
 
17
17
  private
18
18
 
19
- def set_options
20
- @options = @field.options
21
- end
19
+ def set_options
20
+ @options = @field.options
21
+ end
22
22
 
23
- def options_params
24
- params.fetch(:options, {}).permit!
25
- end
23
+ def options_params
24
+ params.fetch(:options, {}).permit!
25
+ end
26
26
  end
@@ -16,11 +16,11 @@ def update
16
16
 
17
17
  private
18
18
 
19
- def set_validations
20
- @validations = @field.validations
21
- end
19
+ def set_validations
20
+ @validations = @field.validations
21
+ end
22
22
 
23
- def validations_params
24
- params.fetch(:validations, {}).permit!
25
- end
23
+ def validations_params
24
+ params.fetch(:validations, {}).permit!
25
+ end
26
26
  end
@@ -7,8 +7,8 @@ class Forms::ApplicationController < ApplicationController
7
7
 
8
8
  protected
9
9
 
10
- # Use callbacks to share common setup or constraints between actions.
11
- def set_form
12
- @form = Form.find(params[:form_id])
13
- end
10
+ # Use callbacks to share common setup or constraints between actions.
11
+ def set_form
12
+ @form = Form.find(params[:form_id])
13
+ end
14
14
  end
@@ -44,13 +44,13 @@ def destroy
44
44
 
45
45
  private
46
46
 
47
- # Use callbacks to share common setup or constraints between actions.
48
- def set_field
49
- @field = @form.fields.find(params[:id])
50
- end
47
+ # Use callbacks to share common setup or constraints between actions.
48
+ def set_field
49
+ @field = @form.fields.find(params[:id])
50
+ end
51
51
 
52
- # Only allow a trusted parameter "white list" through.
53
- def field_params
54
- params.fetch(:field, {}).permit(:name, :label, :hint, :accessibility, :type)
55
- end
52
+ # Only allow a trusted parameter "white list" through.
53
+ def field_params
54
+ params.fetch(:field, {}).permit(:name, :label, :hint, :accessibility, :type)
55
+ end
56
56
  end
@@ -7,13 +7,13 @@ class Formulas::ApplicationController < ApplicationController
7
7
 
8
8
  protected
9
9
 
10
- # Use callbacks to share common setup or constraints between actions.
11
- def set_form
12
- @form = Form.find(params[:form_id])
13
- end
10
+ # Use callbacks to share common setup or constraints between actions.
11
+ def set_form
12
+ @form = Form.find(params[:form_id])
13
+ end
14
14
 
15
- def set_formula
16
- @formula = @form.formulas.find(params[:formula_id])
17
- end
15
+ def set_formula
16
+ @formula = @form.formulas.find(params[:formula_id])
17
+ end
18
18
  end
19
19
  end
@@ -18,12 +18,12 @@ def create
18
18
 
19
19
  private
20
20
 
21
- def set_virtual_model
22
- @virtual_model = @form.to_virtual_model
23
- end
21
+ def set_virtual_model
22
+ @virtual_model = @form.to_virtual_model
23
+ end
24
24
 
25
- def form_record_params
26
- params.fetch(:form_record, {}).permit!
27
- end
25
+ def form_record_params
26
+ params.fetch(:form_record, {}).permit!
27
+ end
28
28
  end
29
29
  end
@@ -44,13 +44,13 @@ def destroy
44
44
 
45
45
  private
46
46
 
47
- # Use callbacks to share common setup or constraints between actions.
48
- def set_formula
49
- @formula = @form.formulas.find(params[:id])
50
- end
47
+ # Use callbacks to share common setup or constraints between actions.
48
+ def set_formula
49
+ @formula = @form.formulas.find(params[:id])
50
+ end
51
51
 
52
- # Only allow a trusted parameter "white list" through.
53
- def formula_params
54
- params.fetch(:formula, {}).permit(:name, :body)
55
- end
52
+ # Only allow a trusted parameter "white list" through.
53
+ def formula_params
54
+ params.fetch(:formula, {}).permit(:name, :body)
55
+ end
56
56
  end
@@ -46,13 +46,13 @@ def destroy
46
46
 
47
47
  private
48
48
 
49
- # Use callbacks to share common setup or constraints between actions.
50
- def set_form
51
- @form = Form.find(params[:id])
52
- end
49
+ # Use callbacks to share common setup or constraints between actions.
50
+ def set_form
51
+ @form = Form.find(params[:id])
52
+ end
53
53
 
54
- # Only allow a trusted parameter "white list" through.
55
- def form_params
56
- params.fetch(:form, {}).permit(:title, :description)
57
- end
54
+ # Only allow a trusted parameter "white list" through.
55
+ def form_params
56
+ params.fetch(:form, {}).permit(:title, :description)
57
+ end
58
58
  end
@@ -5,8 +5,8 @@ class NestedForms::ApplicationController < ApplicationController
5
5
 
6
6
  protected
7
7
 
8
- # Use callbacks to share common setup or constraints between actions.
9
- def set_nested_form
10
- @nested_form = NestedForm.find(params[:nested_form_id])
11
- end
8
+ # Use callbacks to share common setup or constraints between actions.
9
+ def set_nested_form
10
+ @nested_form = NestedForm.find(params[:nested_form_id])
11
+ end
12
12
  end
@@ -38,13 +38,13 @@ def destroy
38
38
 
39
39
  private
40
40
 
41
- # Use callbacks to share common setup or constraints between actions.
42
- def set_field
43
- @field = @nested_form.fields.find(params[:id])
44
- end
41
+ # Use callbacks to share common setup or constraints between actions.
42
+ def set_field
43
+ @field = @nested_form.fields.find(params[:id])
44
+ end
45
45
 
46
- # Only allow a trusted parameter "white list" through.
47
- def field_params
48
- params.fetch(:field, {}).permit(:name, :label, :hint, :accessibility, :type)
49
- end
46
+ # Only allow a trusted parameter "white list" through.
47
+ def field_params
48
+ params.fetch(:field, {}).permit(:name, :label, :hint, :accessibility, :type)
49
+ end
50
50
  end
@@ -38,7 +38,7 @@ def create
38
38
 
39
39
  private
40
40
 
41
- def set_source
42
- @source = params.fetch(:source, "")
43
- end
41
+ def set_source
42
+ @source = params.fetch(:source, "")
43
+ end
44
44
  end
@@ -3,9 +3,7 @@
3
3
  class TimeZonesController < ApplicationController
4
4
  def update
5
5
  @time_zone = ActiveSupport::TimeZone[params[:time_zone]]
6
- unless @time_zone
7
- return render :not_found
8
- end
6
+ return render :not_found unless @time_zone
9
7
 
10
8
  session[:current_time_zone] = params[:time_zone]
11
9
 
@@ -21,7 +21,7 @@ def run(string, payload: nil, instruction_quota_start: nil)
21
21
  payload: payload
22
22
  },
23
23
  instruction_quota_start: instruction_quota_start,
24
- environment_variables: {"TZ" => Time.zone.name}
24
+ environment_variables: { "TZ" => Time.zone.name }
25
25
  end
26
26
 
27
27
  def run_inline(string, payload: nil, instruction_quota_start: nil)
@@ -25,7 +25,7 @@ class ExclusionOptions < FieldOptions
25
25
  def interpret_to(model, field_name, _accessibility, _options = {})
26
26
  return if self.in.empty?
27
27
 
28
- options = {in: self.in}
28
+ options = { in: self.in }
29
29
  options[:message] = message if message.present?
30
30
 
31
31
  model.validates field_name, exclusion: options, allow_blank: true
@@ -33,7 +33,7 @@ def interpret_to(model, field_name, _accessibility, _options = {})
33
33
 
34
34
  with = Regexp.new(self.with)
35
35
 
36
- options = {with: with}
36
+ options = { with: with }
37
37
  options[:message] = message if message.present?
38
38
 
39
39
  model.validates field_name, format: options, allow_blank: true
@@ -25,7 +25,7 @@ class InclusionOptions < FieldOptions
25
25
  def interpret_to(model, field_name, _accessibility, _options = {})
26
26
  return if self.in.empty?
27
27
 
28
- options = {in: self.in}
28
+ options = { in: self.in }
29
29
  options[:message] = message if message.present?
30
30
 
31
31
  model.validates field_name, inclusion: options, allow_blank: true
@@ -43,7 +43,7 @@ def interpret_to(model, field_name, _accessibility, _options = {})
43
43
  return if minimum.zero? && maximum.zero? && is.zero?
44
44
 
45
45
  if is.positive?
46
- model.validates field_name, length: {is: is}, allow_blank: true
46
+ model.validates field_name, length: { is: is }, allow_blank: true
47
47
  return
48
48
  end
49
49
 
@@ -37,31 +37,31 @@ def type_key
37
37
 
38
38
  protected
39
39
 
40
- def interpret_validations_to(model, accessibility, overrides = {})
41
- return unless accessibility == :read_and_write
42
-
43
- validations_overrides = overrides.fetch(:validations) { {} }
44
- validations =
45
- if validations_overrides.any?
46
- self.validations.dup.update(validations_overrides)
47
- else
48
- self.validations
49
- end
50
-
51
- validations.interpret_to(model, name, accessibility)
52
- end
53
-
54
- def interpret_extra_to(model, accessibility, overrides = {})
55
- options_overrides = overrides.fetch(:options) { {} }
56
- options =
57
- if options_overrides.any?
58
- self.options.dup.update(options_overrides)
59
- else
60
- self.options
61
- end
62
-
63
- options.interpret_to(model, name, accessibility)
64
- end
40
+ def interpret_validations_to(model, accessibility, overrides = {})
41
+ return unless accessibility == :read_and_write
42
+
43
+ validations_overrides = overrides.fetch(:validations) { {} }
44
+ validations =
45
+ if validations_overrides.any?
46
+ self.validations.dup.update(validations_overrides)
47
+ else
48
+ self.validations
49
+ end
50
+
51
+ validations.interpret_to(model, name, accessibility)
52
+ end
53
+
54
+ def interpret_extra_to(model, accessibility, overrides = {})
55
+ options_overrides = overrides.fetch(:options) { {} }
56
+ options =
57
+ if options_overrides.any?
58
+ self.options.dup.update(options_overrides)
59
+ else
60
+ self.options
61
+ end
62
+
63
+ options.interpret_to(model, name, accessibility)
64
+ end
65
65
  end
66
66
 
67
67
  require_dependency "fields"
@@ -17,82 +17,76 @@ def serializable_hash(options = {})
17
17
 
18
18
  private
19
19
 
20
- def _assign_attribute(k, v)
21
- if self.class._embeds_reflections.has_key?(k)
22
- public_send("#{k}_attributes=", v)
23
- elsif respond_to?("#{k}=")
24
- public_send("#{k}=", v)
20
+ def _assign_attribute(k, v)
21
+ if self.class._embeds_reflections.key?(k)
22
+ public_send("#{k}_attributes=", v)
23
+ elsif respond_to?("#{k}=")
24
+ public_send("#{k}=", v)
25
+ end
25
26
  end
26
- end
27
27
 
28
- class << self
29
- def _embeds_reflections
30
- _reflections.select { |_, v| v.is_a? ActiveEntity::Reflection::EmbeddedAssociationReflection }
31
- end
28
+ class << self
29
+ def _embeds_reflections
30
+ _reflections.select { |_, v| v.is_a? ActiveEntity::Reflection::EmbeddedAssociationReflection }
31
+ end
32
32
 
33
- def model_version
34
- 1
35
- end
33
+ def model_version
34
+ 1
35
+ end
36
36
 
37
- def root_key_for_serialization
38
- "#{self}.#{model_version}"
39
- end
37
+ def root_key_for_serialization
38
+ "#{self}.#{model_version}"
39
+ end
40
40
 
41
- def dump(obj)
42
- return YAML.dump({}) unless obj
41
+ def dump(obj)
42
+ return YAML.dump({}) unless obj
43
43
 
44
- serializable_hash =
45
- if obj.respond_to?(:serializable_hash)
46
- obj.serializable_hash
47
- elsif obj.respond_to?(:to_hash)
48
- obj.to_hash
49
- else
50
- raise ArgumentError, "`obj` required can be cast to `Hash` -- #{obj.class}"
51
- end.stringify_keys
44
+ serializable_hash =
45
+ if obj.respond_to?(:serializable_hash)
46
+ obj.serializable_hash
47
+ elsif obj.respond_to?(:to_hash)
48
+ obj.to_hash
49
+ else
50
+ raise ArgumentError, "`obj` required can be cast to `Hash` -- #{obj.class}"
51
+ end.stringify_keys
52
52
 
53
- data = {root_key_for_serialization => serializable_hash}
54
- if keeping_old_serialization
55
- data.reverse_merge! obj.raw_attributes
56
- end
53
+ data = { root_key_for_serialization => serializable_hash }
54
+ data.reverse_merge! obj.raw_attributes if keeping_old_serialization
57
55
 
58
- YAML.dump(data)
59
- end
56
+ YAML.dump(data)
57
+ end
60
58
 
61
- def load(yaml_or_hash)
62
- case yaml_or_hash
63
- when Hash
64
- load_from_hash(yaml_or_hash)
65
- when String
66
- load_from_yaml(yaml_or_hash)
67
- else
68
- new
59
+ def load(yaml_or_hash)
60
+ case yaml_or_hash
61
+ when Hash
62
+ load_from_hash(yaml_or_hash)
63
+ when String
64
+ load_from_yaml(yaml_or_hash)
65
+ else
66
+ new
67
+ end
69
68
  end
70
- end
71
69
 
72
- WHITELIST_CLASSES = [BigDecimal, Date, Time, Symbol].freeze
73
- def load_from_yaml(yaml)
74
- return new if yaml.blank?
70
+ WHITELIST_CLASSES = [BigDecimal, Date, Time, Symbol].freeze
71
+ def load_from_yaml(yaml)
72
+ return new if yaml.blank?
75
73
 
76
- unless yaml.is_a?(String) && /^---/.match?(yaml)
77
- return new
78
- end
74
+ return new unless yaml.is_a?(String) && /^---/.match?(yaml)
79
75
 
80
- decoded = YAML.safe_load(yaml, WHITELIST_CLASSES)
81
- unless decoded.is_a? Hash
82
- return new
83
- end
76
+ decoded = YAML.safe_load(yaml, WHITELIST_CLASSES)
77
+ return new unless decoded.is_a? Hash
84
78
 
85
- record = new decoded[root_key_for_serialization]
86
- record.raw_attributes = decoded.freeze
87
- record
88
- end
79
+ record = new decoded[root_key_for_serialization]
80
+ record.raw_attributes = decoded.freeze
81
+ record
82
+ end
89
83
 
90
- def load_from_hash(hash)
91
- return new if hash.blank?
84
+ def load_from_hash(hash)
85
+ return new if hash.blank?
92
86
 
93
- record = new hash[root_key_for_serialization]
94
- record.raw_attributes = hash.freeze
95
- record
87
+ record = new hash[root_key_for_serialization]
88
+ record.raw_attributes = hash.freeze
89
+ record
90
+ end
96
91
  end
97
- end
98
92
  end