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
@@ -11,14 +11,14 @@ def stored_type
11
11
 
12
12
  protected
13
13
 
14
- def interpret_extra_to(model, accessibility, overrides = {})
15
- super
14
+ def interpret_extra_to(model, accessibility, overrides = {})
15
+ super
16
16
 
17
- model.class_eval <<-CODE, __FILE__, __LINE__ + 1
17
+ model.class_eval <<-CODE, __FILE__, __LINE__ + 1
18
18
  def #{name}=(val)
19
19
  super(val.try(:in_time_zone)&.utc)
20
20
  end
21
- CODE
22
- end
21
+ CODE
22
+ end
23
23
  end
24
24
  end
@@ -11,14 +11,14 @@ def stored_type
11
11
 
12
12
  protected
13
13
 
14
- def interpret_extra_to(model, accessibility, overrides = {})
15
- super
14
+ def interpret_extra_to(model, accessibility, overrides = {})
15
+ super
16
16
 
17
- model.class_eval <<-CODE, __FILE__, __LINE__ + 1
17
+ model.class_eval <<-CODE, __FILE__, __LINE__ + 1
18
18
  def #{name}=(val)
19
19
  super(val.try(:in_time_zone)&.utc)
20
20
  end
21
- CODE
22
- end
21
+ CODE
22
+ end
23
23
  end
24
24
  end
@@ -11,10 +11,10 @@ def stored_type
11
11
 
12
12
  protected
13
13
 
14
- def interpret_extra_to(model, accessibility, _overrides = {})
15
- return if accessibility != :read_and_write
14
+ def interpret_extra_to(model, accessibility, _overrides = {})
15
+ return if accessibility != :read_and_write
16
16
 
17
- model.validates name, numericality: {only_integer: true}, allow_blank: true
18
- end
17
+ model.validates name, numericality: { only_integer: true }, allow_blank: true
18
+ end
19
19
  end
20
20
  end
@@ -21,15 +21,13 @@ def interpret_to(model, overrides: {})
21
21
 
22
22
  overrides[:name] = name
23
23
 
24
- nested_model = nested_form.to_virtual_model(overrides: {_global: {accessibility: accessibility}})
24
+ nested_model = nested_form.to_virtual_model(overrides: { _global: { accessibility: accessibility } })
25
25
 
26
26
  model.nested_models[name] = nested_model
27
27
 
28
28
  model.embeds_many name, anonymous_class: nested_model, validate: true
29
29
  model.accepts_nested_attributes_for name, reject_if: :all_blank
30
- if accessibility == :readonly
31
- model.attr_readonly name
32
- end
30
+ model.attr_readonly name if accessibility == :readonly
33
31
 
34
32
  interpret_validations_to model, accessibility, overrides
35
33
  interpret_extra_to model, accessibility, overrides
@@ -20,9 +20,7 @@ def interpret_to(model, overrides: {})
20
20
  return model if accessibility == :hidden
21
21
 
22
22
  model.attribute name, stored_type, default: [], array_without_blank: true
23
- if accessibility == :readonly
24
- model.attr_readonly name
25
- end
23
+ model.attr_readonly name if accessibility == :readonly
26
24
 
27
25
  interpret_validations_to model, accessibility, overrides
28
26
  interpret_extra_to model, accessibility, overrides
@@ -32,11 +30,11 @@ def interpret_to(model, overrides: {})
32
30
 
33
31
  protected
34
32
 
35
- def interpret_extra_to(model, accessibility, overrides = {})
36
- super
37
- return if accessibility != :read_and_write || !options.strict_select
33
+ def interpret_extra_to(model, accessibility, overrides = {})
34
+ super
35
+ return if accessibility != :read_and_write || !options.strict_select
38
36
 
39
- model.validates name, subset: {in: choices.pluck(:label)}, allow_blank: true
40
- end
37
+ model.validates name, subset: { in: choices.pluck(:label) }, allow_blank: true
38
+ end
41
39
  end
42
40
  end
@@ -19,15 +19,13 @@ def interpret_to(model, overrides: {})
19
19
  accessibility = overrides.fetch(:accessibility, self.accessibility)
20
20
  return model if accessibility == :hidden
21
21
 
22
- nested_model = nested_form.to_virtual_model(overrides: {_global: {accessibility: accessibility}})
22
+ nested_model = nested_form.to_virtual_model(overrides: { _global: { accessibility: accessibility } })
23
23
 
24
24
  model.nested_models[name] = nested_model
25
25
 
26
26
  model.embeds_one name, anonymous_class: nested_model, validate: true
27
27
  model.accepts_nested_attributes_for name, reject_if: :all_blank
28
- if accessibility == :readonly
29
- model.attr_readonly name
30
- end
28
+ model.attr_readonly name if accessibility == :readonly
31
29
 
32
30
  interpret_validations_to model, accessibility, overrides
33
31
  interpret_extra_to model, accessibility, overrides
@@ -84,17 +84,17 @@ class DateField < FieldOptions
84
84
  if: %i[begin_from_date? end_to_date?]
85
85
 
86
86
  validates :end_to,
87
- exclusion: {in: %w[today]},
87
+ exclusion: { in: %w[today] },
88
88
  if: [:begin_from_today?]
89
89
 
90
90
  validates :end_to,
91
- exclusion: {in: %w[days_since_begin]},
91
+ exclusion: { in: %w[days_since_begin] },
92
92
  if: [:begin_from_days_before_end?]
93
93
 
94
94
  def interpret_to(model, field_name, accessibility, _options = {})
95
95
  return unless accessibility == :read_and_write
96
96
 
97
- timeliness = {type: :date}
97
+ timeliness = { type: :date }
98
98
 
99
99
  if begin_from_today?
100
100
  begin_days_offset = begin_from_today_days_offset.days
@@ -105,7 +105,7 @@ def interpret_to(model, field_name, accessibility, _options = {})
105
105
  days_before_end = self.days_before_end.days
106
106
  if end_to_today?
107
107
  end_days_offset = end_to_today_days_offset.days
108
- timeliness[:on_or_after] = -> {
108
+ timeliness[:on_or_after] = lambda {
109
109
  Time.zone.today + end_days_offset - days_before_end
110
110
  }
111
111
  elsif end_to_date?
@@ -122,7 +122,7 @@ def interpret_to(model, field_name, accessibility, _options = {})
122
122
  days_since_begin = self.days_since_begin.days
123
123
  if begin_from_today?
124
124
  begin_days_offset = begin_from_today_days_offset.days
125
- timeliness[:on_or_before] = -> {
125
+ timeliness[:on_or_before] = lambda {
126
126
  Time.zone.today + begin_days_offset + days_since_begin
127
127
  }
128
128
  elsif begin_from_date?
@@ -84,17 +84,17 @@ class DatetimeField < FieldOptions
84
84
  if: %i[begin_from_time? end_to_time?]
85
85
 
86
86
  validates :end_to,
87
- exclusion: {in: %w[now]},
87
+ exclusion: { in: %w[now] },
88
88
  if: [:begin_from_now?]
89
89
 
90
90
  validates :end_to,
91
- exclusion: {in: %w[minutes_since_begin]},
91
+ exclusion: { in: %w[minutes_since_begin] },
92
92
  if: [:begin_from_minutes_before_end?]
93
93
 
94
94
  def interpret_to(model, field_name, accessibility, _options = {})
95
95
  return unless accessibility == :read_and_write
96
96
 
97
- timeliness = {type: :datetime}
97
+ timeliness = { type: :datetime }
98
98
 
99
99
  if begin_from_now?
100
100
  begin_minutes_offset = begin_from_now_minutes_offset.minutes.to_i
@@ -105,7 +105,7 @@ def interpret_to(model, field_name, accessibility, _options = {})
105
105
  minutes_before_end = self.minutes_before_end.minutes
106
106
  if end_to_now?
107
107
  end_minutes_offset = end_to_now_minutes_offset.minutes.to_i
108
- timeliness[:on_or_after] = -> {
108
+ timeliness[:on_or_after] = lambda {
109
109
  Time.zone.now.change(sec: 0, usec: 0) + end_minutes_offset - minutes_before_end
110
110
  }
111
111
  elsif end_to_time?
@@ -122,7 +122,7 @@ def interpret_to(model, field_name, accessibility, _options = {})
122
122
  minutes_since_begin = self.minutes_since_begin.minutes.to_i
123
123
  if begin_from_now?
124
124
  begin_minutes_offset = begin_from_now_minutes_offset.minutes.to_i
125
- timeliness[:on_or_before] = -> {
125
+ timeliness[:on_or_before] = lambda {
126
126
  Time.zone.now.change(sec: 0, usec: 0) + begin_minutes_offset + minutes_since_begin
127
127
  }
128
128
  elsif begin_from_time?
@@ -15,11 +15,11 @@ def attached_choices?
15
15
 
16
16
  protected
17
17
 
18
- def interpret_extra_to(model, accessibility, overrides = {})
19
- super
20
- return if accessibility != :read_and_write || !options.strict_select
18
+ def interpret_extra_to(model, accessibility, overrides = {})
19
+ super
20
+ return if accessibility != :read_and_write || !options.strict_select
21
21
 
22
- model.validates name, inclusion: {in: choices.pluck(:label)}, allow_blank: true
23
- end
22
+ model.validates name, inclusion: { in: choices.pluck(:label) }, allow_blank: true
23
+ end
24
24
  end
25
25
  end
File without changes
@@ -30,7 +30,7 @@ def integer_only?
30
30
  end
31
31
 
32
32
  def to_builder_options
33
- {min: min, max: max, step: step, required: required?}.reject { |_, v| v.blank? }
33
+ { min: min, max: max, step: step, required: required? }.reject { |_, v| v.blank? }
34
34
  end
35
35
  end
36
36
  end
@@ -3,7 +3,7 @@
3
3
 
4
4
  <%= tag.div id: field.name, class: "collection" do %>
5
5
  <%= f.fields_for field.name do |ff| %>
6
- <%= render "_form_core/fields/nested_form", f: ff, field: field, form: field.nested_form %>
6
+ <%= render "_form_core/fields/nested_form", f: ff, field: field, form: field.nested_form, nesting: false %>
7
7
  <% end %>
8
8
 
9
9
  <div class="links">
@@ -12,7 +12,7 @@
12
12
  class: "button is-small",
13
13
  partial: "_form_core/fields/nested_form",
14
14
  render_options: {
15
- locals: {field: field, form: field.nested_form}
15
+ locals: {field: field, form: field.nested_form, nesting: true}
16
16
  } %>
17
17
  <% end %>
18
18
  <% if field.hint.present? %>
@@ -1,7 +1,7 @@
1
1
  <div class="field">
2
2
  <%= f.label field.name, field.label, class: 'label' %>
3
3
  <div class="control">
4
- <%= f.select field.name, field.options_for_select, {include_blank: field.include_blank?}, id: field.id, required: field.required, disabled: field.access_readonly?, multiple: true %>
4
+ <%= f.select field.name, field.options_for_select, {include_blank: field.include_blank?}, id: field.id, class: field.id, required: field.required, disabled: field.access_readonly?, multiple: true %>
5
5
  </div>
6
6
  <% if field.hint.present? %>
7
7
  <p class="help"><%= field.hint %></p>
@@ -9,10 +9,18 @@
9
9
  </div>
10
10
 
11
11
  <script>
12
+ <% nesting ||= false %>
13
+ <% if nesting %>
14
+ $("select[class='<%= field.id %>'][class!='selectized']").selectize({
15
+ create: <%= field.can_custom_value? %>,
16
+ maxItems: <%= field.max_items_size %>
17
+ });
18
+ <% else %>
12
19
  document.addEventListener("turbolinks:load", function() {
13
- $('#<%= field.id %>').selectize({
20
+ $("select[class='<%= field.id %>'][class!='selectized']").selectize({
14
21
  create: <%= field.can_custom_value? %>,
15
22
  maxItems: <%= field.max_items_size %>
16
23
  });
17
24
  });
25
+ <% end %>
18
26
  </script>
@@ -1,3 +1,5 @@
1
+ <% nesting ||= false %>
2
+
1
3
  <div class="nested_form">
2
4
  <% if f.object.errors.any? %>
3
5
  <article class="message is-danger">
@@ -23,7 +25,7 @@
23
25
  <% form.fields.each do |field| %>
24
26
  <% field = present(field, target: f.object) %>
25
27
  <% unless field.access_hidden? %>
26
- <%= render "_form_core/fields/#{field.type_key}", f: f, field: field %>
28
+ <%= render "_form_core/fields/#{field.type_key}", f: f, field: field, nesting: nesting %>
27
29
  <% end %>
28
30
  <% end %>
29
31
 
@@ -3,7 +3,7 @@
3
3
 
4
4
  <%= tag.div id: field.name, class: "collection" do %>
5
5
  <%= f.fields_for field.name do |ff| %>
6
- <%= render "_form_core/fields/nested_form", f: ff, field: field, form: field.nested_form %>
6
+ <%= render "_form_core/fields/nested_form", f: ff, field: field, form: field.nested_form, nesting: false %>
7
7
  <% end %>
8
8
 
9
9
  <div class="links">
@@ -13,7 +13,7 @@
13
13
  class: "button is-small",
14
14
  partial: "_form_core/fields/nested_form",
15
15
  render_options: {
16
- locals: {field: field, form: field.nested_form}
16
+ locals: {field: field, form: field.nested_form, nesting: true}
17
17
  } %>
18
18
  <% end %>
19
19
  <% if field.hint.present? %>
@@ -1,7 +1,7 @@
1
1
  <div class="field">
2
2
  <%= f.label field.name, field.label, class: 'label' %>
3
3
  <div class="control">
4
- <%= f.select field.name, field.options_for_select, {include_blank: field.include_blank?}, id: field.id, required: field.required, disabled: field.access_readonly? %>
4
+ <%= f.select field.name, field.options_for_select, {include_blank: field.include_blank?}, id: field.id, class: field.id, required: field.required, disabled: field.access_readonly? %>
5
5
  </div>
6
6
  <% if field.hint.present? %>
7
7
  <p class="help"><%= field.hint %></p>
@@ -9,9 +9,16 @@
9
9
  </div>
10
10
 
11
11
  <script>
12
+ <% nesting ||= false %>
13
+ <% if nesting %>
14
+ $("select[class='<%= field.id %>'][class!='selectized']").selectize({
15
+ create: <%= field.can_custom_value? %>
16
+ });
17
+ <% else %>
12
18
  document.addEventListener("turbolinks:load", function() {
13
- $('#<%= field.id %>').selectize({
19
+ $("select[class='<%= field.id %>'][class!='selectized']").selectize({
14
20
  create: <%= field.can_custom_value? %>
15
21
  });
16
22
  });
23
+ <% end %>
17
24
  </script>
@@ -31,6 +31,13 @@ class Application < Rails::Application
31
31
  # Application configuration can go into files in config/initializers
32
32
  # -- all .rb files in that directory are automatically loaded after loading
33
33
  # the framework and any gems in your application.
34
- config.i18n.fallbacks = [I18n.default_locale]
34
+
35
+ Rails.autoloaders.main.ignore("#{Rails.root}/app/overrides")
36
+
37
+ config.to_prepare do
38
+ Dir.glob(Rails.root + "app/overrides/**/*_override*.rb").each do |c|
39
+ require_dependency(c)
40
+ end
41
+ end
35
42
  end
36
43
  end
@@ -4,7 +4,7 @@
4
4
  class CreateForms < ActiveRecord::Migration[5.2]
5
5
  def change
6
6
  create_table :forms do |t|
7
- t.string :name, null: false, index: {unique: true}
7
+ t.string :name, null: false, index: { unique: true }
8
8
  t.string :type, null: false, index: true
9
9
 
10
10
  t.timestamps
@@ -5,8 +5,8 @@ class BigDecimal
5
5
 
6
6
  private
7
7
 
8
- def to_msgpack_with_packer(packer)
9
- packer.write_string to_s("F")
10
- packer
11
- end
8
+ def to_msgpack_with_packer(packer)
9
+ packer.write_string to_s("F")
10
+ packer
11
+ end
12
12
  end
@@ -5,8 +5,8 @@ class Date
5
5
 
6
6
  private
7
7
 
8
- def to_msgpack_with_packer(packer)
9
- packer.write_array [year, month, day]
10
- packer
11
- end
8
+ def to_msgpack_with_packer(packer)
9
+ packer.write_array [year, month, day]
10
+ packer
11
+ end
12
12
  end
@@ -5,8 +5,8 @@ class Time
5
5
 
6
6
  private
7
7
 
8
- def to_msgpack_with_packer(packer)
9
- packer.write_array to_a[0..5].reverse # [sec, min, hour, day, month, year, wday, yday, isdst, zone]
10
- packer
11
- end
8
+ def to_msgpack_with_packer(packer)
9
+ packer.write_array to_a[0..5].reverse # [sec, min, hour, day, month, year, wday, yday, isdst, zone]
10
+ packer
11
+ end
12
12
  end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
6
+ driven_by :selenium, using: :chrome, screen_size: [1400, 1400]
7
+ end
@@ -8,14 +8,14 @@
8
8
  it "processes an output message" do
9
9
  io = StringIO.new(packer.pack([
10
10
  :output,
11
- extracted: {dog: "fine"},
11
+ extracted: { dog: "fine" },
12
12
  stdout: "hello"
13
13
  ]))
14
14
 
15
15
  message_processor.process_all(io)
16
16
  expect(message_processor.to_result).to eq(
17
17
  ScriptCore::Result.new(
18
- output: {dog: "fine"},
18
+ output: { dog: "fine" },
19
19
  stdout: "hello",
20
20
  stat: ScriptCore::Stat::Null,
21
21
  errors: [],
@@ -160,7 +160,7 @@
160
160
  stdout: "",
161
161
  stat: ScriptCore::Stat::Null,
162
162
  errors: [],
163
- measurements: {transmogrification: 14}
163
+ measurements: { transmogrification: 14 }
164
164
  )
165
165
  )
166
166
  end
@@ -184,7 +184,7 @@
184
184
  stdout: "",
185
185
  stat: ScriptCore::Stat::Null,
186
186
  errors: [],
187
- measurements: {transmogrification: 26}
187
+ measurements: { transmogrification: 26 }
188
188
  )
189
189
  )
190
190
  end