marty 2.5.2 → 2.5.4

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 (181) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +4 -0
  3. data/.rubocop.yml +7 -0
  4. data/.rubocop_todo.yml +11 -589
  5. data/Gemfile +9 -9
  6. data/Gemfile.lock +1 -1
  7. data/Rakefile +1 -3
  8. data/app/components/marty/api_auth_view.rb +3 -3
  9. data/app/components/marty/api_config_view.rb +8 -8
  10. data/app/components/marty/api_log_view.rb +16 -20
  11. data/app/components/marty/auth_app.rb +6 -6
  12. data/app/components/marty/base_rule_view.rb +27 -19
  13. data/app/components/marty/config_view.rb +12 -9
  14. data/app/components/marty/data_grid_view.rb +26 -26
  15. data/app/components/marty/delorean_rule_view.rb +0 -1
  16. data/app/components/marty/event_view.rb +27 -27
  17. data/app/components/marty/extras/layout.rb +26 -26
  18. data/app/components/marty/extras/misc.rb +2 -2
  19. data/app/components/marty/grid.rb +13 -13
  20. data/app/components/marty/grid_append_only.rb +0 -1
  21. data/app/components/marty/import_type_view.rb +13 -13
  22. data/app/components/marty/import_view.rb +17 -16
  23. data/app/components/marty/log_view.rb +16 -14
  24. data/app/components/marty/main_auth_app.rb +59 -59
  25. data/app/components/marty/main_auth_app/client/main_auth_app.js +3 -3
  26. data/app/components/marty/mcfly_grid_panel.rb +10 -10
  27. data/app/components/marty/new_posting_form.rb +11 -11
  28. data/app/components/marty/new_posting_window.rb +0 -1
  29. data/app/components/marty/posting_grid.rb +12 -13
  30. data/app/components/marty/promise_view.rb +6 -6
  31. data/app/components/marty/report_form.rb +50 -53
  32. data/app/components/marty/report_select.rb +27 -27
  33. data/app/components/marty/reporting.rb +4 -4
  34. data/app/components/marty/script_form.rb +40 -42
  35. data/app/components/marty/script_grid.rb +24 -24
  36. data/app/components/marty/script_tester.rb +40 -42
  37. data/app/components/marty/scripting.rb +25 -27
  38. data/app/components/marty/simple_app.rb +24 -9
  39. data/app/components/marty/tag_grid.rb +12 -13
  40. data/app/components/marty/user_view.rb +35 -35
  41. data/app/controllers/marty/application_controller.rb +3 -4
  42. data/app/controllers/marty/components_controller.rb +1 -1
  43. data/app/controllers/marty/delayed_job_controller.rb +1 -0
  44. data/app/controllers/marty/diagnostic/controller.rb +4 -6
  45. data/app/controllers/marty/job_controller.rb +6 -6
  46. data/app/controllers/marty/report_controller.rb +11 -11
  47. data/app/controllers/marty/rpc_controller.rb +15 -16
  48. data/app/helpers/marty/script_set.rb +4 -4
  49. data/app/models/marty/api_auth.rb +4 -5
  50. data/app/models/marty/api_config.rb +1 -1
  51. data/app/models/marty/base.rb +9 -8
  52. data/app/models/marty/base_rule.rb +18 -13
  53. data/app/models/marty/config.rb +4 -5
  54. data/app/models/marty/data_grid.rb +157 -181
  55. data/app/models/marty/delorean_rule.rb +63 -62
  56. data/app/models/marty/enum.rb +1 -1
  57. data/app/models/marty/event.rb +56 -59
  58. data/app/models/marty/helper.rb +38 -6
  59. data/app/models/marty/import_type.rb +6 -6
  60. data/app/models/marty/log.rb +3 -2
  61. data/app/models/marty/name_validator.rb +3 -2
  62. data/app/models/marty/pg_enum.rb +3 -4
  63. data/app/models/marty/posting.rb +20 -24
  64. data/app/models/marty/promise.rb +28 -30
  65. data/app/models/marty/script.rb +30 -28
  66. data/app/models/marty/tag.rb +8 -8
  67. data/app/models/marty/token.rb +2 -2
  68. data/app/models/marty/user.rb +24 -23
  69. data/app/models/marty/vw_promise.rb +10 -11
  70. data/config/routes.rb +2 -2
  71. data/delorean/blame_report.dl +268 -0
  72. data/{spec/dummy/delorean/fields.dl → delorean/marty_fields.dl} +8 -0
  73. data/delorean/table_report.dl +34 -0
  74. data/docker-compose.dummy.yml +2 -3
  75. data/lib/marty/aws/base.rb +8 -8
  76. data/lib/marty/aws/request.rb +4 -4
  77. data/lib/marty/cache_adapters/mcfly_ruby_cache.rb +1 -0
  78. data/lib/marty/content_handler.rb +25 -25
  79. data/lib/marty/data_change.rb +49 -71
  80. data/lib/marty/data_conversion.rb +20 -28
  81. data/lib/marty/data_exporter.rb +25 -28
  82. data/lib/marty/data_importer.rb +25 -27
  83. data/lib/marty/engine.rb +1 -2
  84. data/lib/marty/json_schema.rb +22 -24
  85. data/lib/marty/logger.rb +6 -9
  86. data/lib/marty/mcfly_model.rb +20 -24
  87. data/lib/marty/migrations.rb +37 -35
  88. data/lib/marty/monkey.rb +33 -33
  89. data/lib/marty/permissions.rb +18 -18
  90. data/lib/marty/promise_job.rb +17 -17
  91. data/lib/marty/promise_proxy.rb +6 -6
  92. data/lib/marty/relation.rb +6 -7
  93. data/lib/marty/rpc_call.rb +13 -12
  94. data/lib/marty/rule_script_set.rb +32 -28
  95. data/lib/marty/schema_helper.rb +37 -51
  96. data/lib/marty/util.rb +25 -24
  97. data/lib/marty/version.rb +1 -1
  98. data/lib/marty/xl.rb +121 -115
  99. data/make-dummy.mk +3 -0
  100. data/marty.gemspec +21 -21
  101. data/other/marty/api/base.rb +34 -35
  102. data/other/marty/diagnostic/aws/ec2_instance.rb +8 -8
  103. data/other/marty/diagnostic/base.rb +13 -14
  104. data/other/marty/diagnostic/collection.rb +2 -1
  105. data/other/marty/diagnostic/connections.rb +8 -6
  106. data/other/marty/diagnostic/database.rb +1 -0
  107. data/other/marty/diagnostic/delayed_job_version.rb +7 -9
  108. data/other/marty/diagnostic/delayed_job_worker_total_count.rb +1 -1
  109. data/other/marty/diagnostic/delayed_job_workers.rb +1 -1
  110. data/other/marty/diagnostic/environment_variables.rb +17 -15
  111. data/other/marty/diagnostic/fatal.rb +1 -1
  112. data/other/marty/diagnostic/node.rb +5 -9
  113. data/other/marty/diagnostic/nodes.rb +7 -5
  114. data/other/marty/diagnostic/packer.rb +7 -7
  115. data/other/marty/diagnostic/reporter.rb +24 -27
  116. data/other/marty/diagnostic/version.rb +3 -5
  117. data/script/rails +2 -1
  118. data/spec/controllers/application_controller_spec.rb +6 -6
  119. data/spec/controllers/delayed_job_controller_spec.rb +4 -4
  120. data/spec/controllers/diagnostic/controller_spec.rb +59 -60
  121. data/spec/controllers/job_controller_spec.rb +68 -69
  122. data/spec/controllers/rpc_controller_spec.rb +353 -359
  123. data/spec/controllers/rpc_import_spec.rb +15 -16
  124. data/spec/dummy/delorean/blame_report.dl +110 -15
  125. data/spec/dummy/delorean/data_report.dl +4 -4
  126. data/spec/dummy/delorean/marty_fields.dl +63 -0
  127. data/spec/dummy/delorean/table_report.dl +34 -0
  128. data/spec/features/auth_app_spec.rb +1 -2
  129. data/spec/features/data_import_spec.rb +2 -3
  130. data/spec/features/enum_spec.rb +42 -46
  131. data/spec/features/jobs_dashboard_spec.rb +14 -8
  132. data/spec/features/log_view_spec.rb +40 -43
  133. data/spec/features/reporting_spec.rb +15 -15
  134. data/spec/features/rule_spec.rb +195 -190
  135. data/spec/features/scripting_spec.rb +17 -20
  136. data/spec/features/scripting_test_spec.rb +32 -33
  137. data/spec/features/user_view_spec.rb +15 -17
  138. data/spec/job_helper.rb +11 -11
  139. data/spec/lib/data_blame_spec.rb +82 -0
  140. data/spec/lib/data_exporter_spec.rb +31 -32
  141. data/spec/lib/data_importer_spec.rb +382 -395
  142. data/spec/lib/delorean_query_spec.rb +117 -119
  143. data/spec/lib/json_schema_spec.rb +382 -392
  144. data/spec/lib/logger_spec.rb +23 -24
  145. data/spec/lib/mcfly_model_spec.rb +112 -109
  146. data/spec/lib/migrations_spec.rb +10 -10
  147. data/spec/lib/struct_compare_spec.rb +6 -6
  148. data/spec/lib/table_report_spec.rb +90 -0
  149. data/spec/lib/xl_spec.rb +63 -65
  150. data/spec/lib/xl_styles_spec.rb +16 -19
  151. data/spec/models/api_auth_spec.rb +30 -30
  152. data/spec/models/config_spec.rb +32 -32
  153. data/spec/models/data_grid_spec.rb +642 -655
  154. data/spec/models/event_spec.rb +96 -88
  155. data/spec/models/import_type_spec.rb +20 -20
  156. data/spec/models/posting_spec.rb +35 -35
  157. data/spec/models/promise_spec.rb +5 -5
  158. data/spec/models/rule_spec.rb +280 -269
  159. data/spec/models/script_spec.rb +27 -18
  160. data/spec/models/user_spec.rb +9 -9
  161. data/spec/other/diagnostic/base_spec.rb +20 -19
  162. data/spec/other/diagnostic/collection_spec.rb +6 -5
  163. data/spec/other/diagnostic/delayed_job_version_spec.rb +1 -1
  164. data/spec/other/diagnostic/delayed_job_workers_spec.rb +8 -8
  165. data/spec/other/diagnostic/reporter_spec.rb +31 -33
  166. data/spec/spec_helper.rb +5 -5
  167. data/spec/support/chromedriver.rb +3 -5
  168. data/spec/support/components/netzke_combobox.rb +1 -1
  169. data/spec/support/components/netzke_grid.rb +17 -17
  170. data/spec/support/custom_matchers.rb +2 -2
  171. data/spec/support/download_helper.rb +1 -1
  172. data/spec/support/helper.rb +1 -2
  173. data/spec/support/netzke.rb +31 -31
  174. data/spec/support/performance_helper.rb +8 -8
  175. data/spec/support/post_run_logger.rb +1 -2
  176. data/spec/support/setup.rb +1 -4
  177. data/spec/support/shared_connection.rb +2 -2
  178. data/spec/support/structure_compare.rb +21 -22
  179. data/spec/support/suite.rb +1 -2
  180. data/spec/support/users.rb +5 -6
  181. metadata +32 -26
@@ -12,49 +12,49 @@ module Marty::Permissions
12
12
  #
13
13
  # :any gives permission to the action if user belongs to at least 1 role
14
14
  def has_marty_permissions(attrs)
15
- raise "bad attrs" unless attrs.is_a?(Hash)
16
- raise "unknown role" unless
15
+ raise 'bad attrs' unless attrs.is_a?(Hash)
16
+ raise 'unknown role' unless
17
17
  attrs.values.flatten.to_set.subset? (ALL_ROLES << :any)
18
18
 
19
- self.define_singleton_method(:marty_permissions) { attrs }
19
+ define_singleton_method(:marty_permissions) { attrs }
20
20
  end
21
21
 
22
22
  def current_user_roles
23
23
  roles = Mcfly.whodunnit.roles rescue []
24
- roles.map {|r| r.name.to_sym}.to_set
24
+ roles.map { |r| r.name.to_sym }.to_set
25
25
  end
26
26
 
27
27
  def can_perform_action?(action)
28
- return false unless self.respond_to?(:marty_permissions)
28
+ return false unless respond_to?(:marty_permissions)
29
29
 
30
- roles = self.current_user_roles
31
- roles = roles << :any if self.has_any_perm?
30
+ roles = current_user_roles
31
+ roles = roles << :any if has_any_perm?
32
32
 
33
- aroles = self.marty_permissions[action.to_sym] || []
33
+ aroles = marty_permissions[action.to_sym] || []
34
34
  # TODO: Use code below when switching to Ruby 2.1
35
35
  # Set[ *aroles].intersect? roles.to_set
36
- (Set[ *aroles] & roles.to_set).length > 0
36
+ !(Set[*aroles] & roles.to_set).empty?
37
37
  end
38
38
 
39
39
  def can_perform_actions
40
- return [] unless self.respond_to?(:marty_permissions)
40
+ return [] unless respond_to?(:marty_permissions)
41
41
 
42
- roles = self.current_user_roles
43
- roles = roles << :any if self.has_any_perm?
42
+ roles = current_user_roles
43
+ roles = roles << :any if has_any_perm?
44
44
 
45
- self.marty_permissions.map { |action, aroles|
45
+ marty_permissions.map do |action, aroles|
46
46
  # TODO: Use code below when switching to Ruby 2.1
47
- #action if Set[ *aroles].intersect? roles.to_set
48
- action if (Set[ *aroles] & roles.to_set).length > 0
49
- }.compact
47
+ # action if Set[ *aroles].intersect? roles.to_set
48
+ action unless (Set[*aroles] & roles.to_set).empty?
49
+ end.compact
50
50
  end
51
51
 
52
52
  # generate has_xxx_perm? methods for all permissions.
53
- Rails.configuration.marty.roles.each { |role|
53
+ Rails.configuration.marty.roles.each do |role|
54
54
  define_method("has_#{role}_perm?") do
55
55
  current_user_roles.member? role
56
56
  end
57
- }
57
+ end
58
58
 
59
59
  def has_any_perm?
60
60
  !(current_user_roles & ALL_ROLES).empty?
@@ -17,12 +17,12 @@ class Delorean::BaseModule::NodeCall
17
17
  # Monkey-patch '|' method for Delorean NodeCall to create promise
18
18
  # jobs and return promise proxy objects.
19
19
  def |(args)
20
-
21
20
  if args.is_a?(String)
22
21
  attr = args
23
22
  args = [attr]
24
23
  else
25
- raise "bad arg to %" unless args.is_a?(Array)
24
+ raise 'bad arg to %' unless args.is_a?(Array)
25
+
26
26
  attr = nil
27
27
  end
28
28
  script, tag = engine.module_name, engine.sset.tag
@@ -30,25 +30,25 @@ class Delorean::BaseModule::NodeCall
30
30
  begin
31
31
  # make sure params is serialzable before starting a Job
32
32
  JSON.dump(params)
33
- rescue => exc
33
+ rescue StandardError => exc
34
34
  raise "non-serializable parameters: #{params} #{exc}"
35
35
  end
36
36
 
37
37
  # log "||||| #{args.inspect} #{params.inspect}"
38
38
 
39
- title = params["p_title"] || "#{script}::#{nn.demodulize}"
40
- timeout = params["p_timeout"] || Marty::Promise::DEFAULT_PROMISE_TIMEOUT
41
- hook = params["p_hook"]
39
+ title = params['p_title'] || "#{script}::#{nn.demodulize}"
40
+ timeout = params['p_timeout'] || Marty::Promise::DEFAULT_PROMISE_TIMEOUT
41
+ hook = params['p_hook']
42
42
  promise = Marty::Promise.
43
43
  create(title: title,
44
44
  user_id: params[:_user_id],
45
45
  parent_id: params[:_parent_id],
46
- )
46
+ )
47
47
  params[:_promise_id] = promise.id
48
48
  begin
49
49
  job = Delayed::Job.enqueue Marty::PromiseJob.
50
50
  new(promise, title, script, tag, nn, params, args, hook)
51
- rescue => exc
51
+ rescue StandardError => exc
52
52
  # log "CALLERR #{exc}"
53
53
  res = Delorean::Engine.grok_runtime_exception(exc)
54
54
  promise.set_start
@@ -63,10 +63,10 @@ class Delorean::BaseModule::NodeCall
63
63
  promise.job_id = job.id
64
64
  promise.save!
65
65
 
66
- evh = params["p_event"]
66
+ evh = params['p_event']
67
67
  if evh
68
- event, klass, subject_id, operation = evh.values_at("event", "klass",
69
- "id", "operation")
68
+ event, klass, subject_id, operation = evh.values_at('event', 'klass',
69
+ 'id', 'operation')
70
70
  if event
71
71
  event.promise_id = promise.id
72
72
  event.save!
@@ -82,11 +82,11 @@ class Delorean::BaseModule::NodeCall
82
82
  end
83
83
  end
84
84
 
85
-
86
85
  class Delorean::Engine
87
86
  def background_eval(node, params, attrs, event = {})
88
- raise "background_eval bad params" unless params.is_a?(Hash)
89
- params["p_event"] = event.each_with_object({}) do |(k, v), h|
87
+ raise 'background_eval bad params' unless params.is_a?(Hash)
88
+
89
+ params['p_event'] = event.each_with_object({}) do |(k, v), h|
90
90
  h[k.to_s] = v
91
91
  end unless event.empty?
92
92
  nc = Delorean::BaseModule::NodeCall.new({}, self, node, params)
@@ -103,7 +103,7 @@ class Marty::PromiseJob < Struct.new(:promise,
103
103
  :params,
104
104
  :attrs,
105
105
  :hook,
106
- )
106
+ )
107
107
  # def log(msg)
108
108
  # open('/tmp/dj.out', 'a') { |f| f.puts msg }
109
109
  # end
@@ -136,7 +136,7 @@ class Marty::PromiseJob < Struct.new(:promise,
136
136
  end
137
137
 
138
138
  # log "DONE #{Process.pid} #{promise.id} #{Time.now.to_f} #{res}"
139
- rescue => exc
139
+ rescue StandardError => exc
140
140
  res = Delorean::Engine.grok_runtime_exception(exc)
141
141
  # log "ERR- #{Process.pid} #{promise.id} #{Time.now.to_f} #{exc}"
142
142
  end
@@ -144,7 +144,7 @@ class Marty::PromiseJob < Struct.new(:promise,
144
144
 
145
145
  begin
146
146
  hook.run(res) if hook
147
- rescue => exc
147
+ rescue StandardError => exc
148
148
  Marty::Util.logger.error "promise hook failed: #{exc}"
149
149
  end
150
150
  end
@@ -14,9 +14,9 @@ class Marty::PromiseProxy < BasicObject
14
14
  :as_json,
15
15
  ]
16
16
 
17
- instance_methods.each {|m| undef_method m unless m =~ /^(__.*|object_id)$/}
17
+ instance_methods.each { |m| undef_method m unless m =~ /^(__.*|object_id)$/ }
18
18
 
19
- def initialize(promise_id, timeout, attr=nil)
19
+ def initialize(promise_id, timeout, attr = nil)
20
20
  promise_id, @timeout, @attr = promise_id, timeout, attr
21
21
  @promise = ::Marty::Promise.find(promise_id)
22
22
  @mutex = ::Mutex.new
@@ -24,7 +24,7 @@ class Marty::PromiseProxy < BasicObject
24
24
  end
25
25
 
26
26
  def as_json(*)
27
- {'__promise__' => [@promise.id, @timeout, @attr]}
27
+ { '__promise__' => [@promise.id, @timeout, @attr] }
28
28
  end
29
29
 
30
30
  def __promise__
@@ -54,7 +54,7 @@ class Marty::PromiseProxy < BasicObject
54
54
  if @result.equal?(NOT_SET)
55
55
  begin
56
56
  @result = @promise.wait_for_result(@timeout)
57
- @result = @result[@attr] if @attr && !@result["error"]
57
+ @result = @result[@attr] if @attr && !@result['error']
58
58
  rescue ::Exception => exc
59
59
  @result = ::Delorean::Engine.grok_runtime_exception(exc)
60
60
  end
@@ -65,7 +65,7 @@ class Marty::PromiseProxy < BasicObject
65
65
  # FIXME: the logic for shape of exceptions from Delorean is spread
66
66
  # all over the place.
67
67
  @result.is_a?(::Hash) &&
68
- @result["error"] ? ::Kernel.raise(@result["error"]) : @result
68
+ @result['error'] ? ::Kernel.raise(@result['error']) : @result
69
69
  end
70
70
 
71
71
  alias_method :force, :__force__
@@ -75,7 +75,7 @@ class Marty::PromiseProxy < BasicObject
75
75
  #
76
76
  # @param [Symbol]
77
77
  # @return [Boolean]
78
- def respond_to?(method, include_all=false)
78
+ def respond_to?(method, include_all = false)
79
79
  METH_SET.member?(method) || __force__.respond_to?(method, include_all)
80
80
  end
81
81
 
@@ -2,13 +2,13 @@ class Marty::Relation
2
2
  # Given a Mcfly class (klass) and a list of classes which can
3
3
  # reference klass, returns instaces of klass which have no references.
4
4
  def self.not_referenced(klass, ref_classes)
5
- col = (klass.name.split('::').last.snakecase + "_id").to_sym
5
+ col = (klass.name.split('::').last.snakecase + '_id').to_sym
6
6
 
7
7
  ids = klass.where(obsoleted_dt: 'infinity').pluck(:group_id)
8
8
 
9
- ref_ids = ref_classes.map { |rclass|
9
+ ref_ids = ref_classes.map do |rclass|
10
10
  rclass.where(obsoleted_dt: 'infinity', col => ids).pluck(col)
11
- }.flatten.uniq
11
+ end.flatten.uniq
12
12
 
13
13
  klass.where(id: ids - ref_ids).to_a
14
14
  end
@@ -18,17 +18,16 @@ class Marty::Relation
18
18
  # mcfly_belongs_to reference from klass.
19
19
  def self.obsoleted_references(klass)
20
20
  assoc_h = Marty::DataConversion.associations(klass)
21
- assoc_h.each_with_object({}) do
22
- |(a, ah), h|
21
+ assoc_h.each_with_object({}) do |(a, ah), h|
23
22
  assoc_class = ah[:assoc_class]
24
23
  foreign_key = ah[:foreign_key]
25
24
 
26
25
  next unless Mcfly.has_mcfly? assoc_class
27
26
 
28
- h[a] = klass.where(obsoleted_dt: 'infinity').map do
29
- |obj|
27
+ h[a] = klass.where(obsoleted_dt: 'infinity').map do |obj|
30
28
  ref_key = obj.send(foreign_key)
31
29
  next unless ref_key
30
+
32
31
  ref = assoc_class.find(ref_key)
33
32
  obj unless Mcfly.is_infinity(ref.obsoleted_dt)
34
33
  end.compact
@@ -1,30 +1,31 @@
1
1
  class Marty::RpcCall
2
2
  # POST to a remote marty
3
- def self.marty_post(host, port, path, script, node, attrs, params, options={},
4
- ssl=false)
3
+ def self.marty_post(host, port, path, script, node, attrs, params, options = {},
4
+ ssl = false)
5
5
  http = Net::HTTP.new(host, port)
6
6
  http.use_ssl = ssl
7
7
  request = Net::HTTP::Post.new(path)
8
8
  request.add_field('Content-Type', 'application/json')
9
9
  request.body = (options + {
10
- "script" => script,
11
- "node" => node,
12
- "attrs" => attrs.to_json,
13
- "params" => params.to_json,
10
+ 'script' => script,
11
+ 'node' => node,
12
+ 'attrs' => attrs.to_json,
13
+ 'params' => params.to_json,
14
14
  }).to_json
15
15
  begin
16
16
  response = http.request(request)
17
- rescue => e
17
+ rescue StandardError => e
18
18
  raise "#{e.message} during RPC call to #{host}:#{port}"
19
19
  end
20
20
 
21
21
  res = JSON.parse(response.body)
22
- raise res["error"] if res.is_a?(Hash) && !res["error"].blank?
22
+ raise res['error'] if res.is_a?(Hash) && !res['error'].blank?
23
+
23
24
  res
24
25
  end
25
26
 
26
- def self.marty_download(host, port, path, job_id, ssl=false)
27
- params = {job_id: job_id}
27
+ def self.marty_download(host, port, path, job_id, ssl = false)
28
+ params = { job_id: job_id }
28
29
  url = path + '?' + URI.encode(URI.encode_www_form(params))
29
30
 
30
31
  http = Net::HTTP.new(host, port)
@@ -33,7 +34,7 @@ class Marty::RpcCall
33
34
 
34
35
  begin
35
36
  http.request(request)
36
- rescue => e
37
+ rescue StandardError => e
37
38
  raise "#{e.message} during download call to #{host}:#{port}"
38
39
  end
39
40
  end
@@ -49,7 +50,7 @@ class Marty::RpcCall
49
50
  begin
50
51
  response = http.request(request)
51
52
  raise "got #{response} during XML call" if response.class != Net::HTTPOK
52
- rescue => e
53
+ rescue StandardError => e
53
54
  raise "#{e.message} during RPC call to #{host}:#{port}#{path}"
54
55
  end
55
56
 
@@ -8,13 +8,15 @@ class Marty::RuleScriptSet < Delorean::AbstractContainer
8
8
  clear_cache
9
9
 
10
10
  def self.node_name
11
- "Node"
11
+ 'Node'
12
12
  end
13
+
13
14
  def self.body_start
14
15
  "#{node_name}:\n"
15
16
  end
17
+
16
18
  def self.body_lines
17
- self.body_start.count("\n")
19
+ body_start.count("\n")
18
20
  end
19
21
 
20
22
  def initialize(pt)
@@ -31,27 +33,28 @@ class Marty::RuleScriptSet < Delorean::AbstractContainer
31
33
  end
32
34
 
33
35
  def write_attr(k, v)
34
- equals, rhs = v == :parameter ? [" =?", ""] :
35
- [" =", "\n" + v.lines.map{|l| " "*8 + l}.join("\n")]
36
+ equals, rhs = v == :parameter ? [' =?', ''] :
37
+ [' =', "\n" + v.lines.map { |l| ' ' * 8 + l }.join("\n")]
36
38
  k + equals + rhs
37
39
  end
38
40
 
39
41
  def paramify_h(h)
40
- "{" + h.keys.reject{|k|k.ends_with?("__")}.
41
- map {|k| %Q("#{k}": #{k}) }.join(",\n") + "}"
42
+ '{' + h.keys.reject { |k| k.ends_with?('__') }.
43
+ map { |k| %Q("#{k}": #{k}) }.join(",\n") + '}'
42
44
  end
43
45
 
44
46
  def self.grid_final_name(dgid)
45
- dgid.ends_with?("_grid") ? dgid + "_result" : dgid + "_grid_result"
47
+ dgid.ends_with?('_grid') ? dgid + '_result' : dgid + '_grid_result'
46
48
  end
49
+
47
50
  def expand_grid_code(h, dgid, dgname, cache, extra_params)
48
51
  final_name = self.class.grid_final_name(dgid)
49
52
  if cache[dgname]
50
- h[final_name] = "#{cache[dgname]}"
53
+ h[final_name] = (cache[dgname]).to_s
51
54
  else
52
55
  h[dgid] = dgname
53
56
  h["#{dgid}_dgp__"] = "dgparams__ + \n" + self.class.indent(paramify_h(h))
54
- lgde = "lookup_grid_h"
57
+ lgde = 'lookup_grid_h'
55
58
  h[final_name] = "Marty::DataGrid.#{lgde}(pt,#{dgid},#{dgid}_dgp__,true)"
56
59
  cache[dgname] = final_name
57
60
  end
@@ -59,8 +62,9 @@ class Marty::RuleScriptSet < Delorean::AbstractContainer
59
62
 
60
63
  def write_code(attrs)
61
64
  return '' if attrs.blank?
65
+
62
66
  newh = attrs.each_with_object({}) do |(k, v), h|
63
- if k.ends_with?("_grid")
67
+ if k.ends_with?('_grid')
64
68
  expand_grid_code(h, k, v, {}, h)
65
69
  else
66
70
  h[k] = v
@@ -72,31 +76,32 @@ class Marty::RuleScriptSet < Delorean::AbstractContainer
72
76
  def grid_code(ruleh)
73
77
  dgcache = {}
74
78
  h = {}
75
- ruleh["grids"].each do |k, v|
76
- expand_grid_code(h, k.ends_with?('_grid')?k:k+'_grid', %Q("#{v}"),
77
- dgcache, {})
79
+ ruleh['grids'].each do |k, v|
80
+ expand_grid_code(h, k.ends_with?('_grid') ? k : k + '_grid', %Q("#{v}"),
81
+ dgcache, {})
78
82
  end
79
83
  h.map { |k, v| write_attr(k, v) }.join("\n") + "\n"
80
84
  end
81
85
 
82
86
  def guard_code(ruleh)
83
- write_code(ruleh["computed_guards"])
87
+ write_code(ruleh['computed_guards'])
84
88
  end
85
89
 
86
90
  def result_code(ruleh)
87
- write_code(ruleh["results"])
91
+ write_code(ruleh['results'])
88
92
  end
89
93
 
90
94
  def grid_init(ruleh)
91
- if ruleh["grids"].present? ||
92
- ruleh["results"].keys.any?{|k|k.ends_with?("_grid")}
93
- write_code({ "pt" => :parameter,
94
- "dgparams__" => :parameter,
95
- })
95
+ if ruleh['grids'].present? ||
96
+ ruleh['results'].keys.any? { |k| k.ends_with?('_grid') }
97
+ write_code('pt' => :parameter,
98
+ 'dgparams__' => :parameter,
99
+ )
96
100
  else
97
101
  ''
98
102
  end
99
103
  end
104
+
100
105
  def get_code(ruleh)
101
106
  grid_i = grid_init(ruleh)
102
107
  grid_c = grid_code(ruleh)
@@ -122,11 +127,12 @@ class Marty::RuleScriptSet < Delorean::AbstractContainer
122
127
  errs[:results] = result_code(ruleh).count("\n")
123
128
  errs
124
129
  end
130
+
125
131
  def get_parse_error_field(ruleh, exc)
126
132
  line = exc.line ? exc.line - self.class.body_lines : 0
127
133
  errs = code_section_counts(ruleh)
128
134
  line_count = 0
129
- errs.each do |k,v|
135
+ errs.each do |k, v|
130
136
  line_count += v
131
137
  return k if line <= line_count
132
138
  end
@@ -134,22 +140,21 @@ class Marty::RuleScriptSet < Delorean::AbstractContainer
134
140
  end
135
141
 
136
142
  def get_engine(ruleh)
137
- begin
138
143
  # if rule is a str => importing a regular Script (i.e. not rule)
139
144
  return sset.get_engine(ruleh) if ruleh.is_a? String
140
145
 
141
146
  # on create rule doesn't have an id => don't cache
142
147
  return sset.parse_check("New RULE #{ruleh['name']}", get_code(ruleh)) unless
143
- ruleh["id"]
148
+ ruleh['id']
144
149
 
145
- rule_pfx = ruleh["classname"].demodulize
150
+ rule_pfx = ruleh['classname'].demodulize
146
151
 
147
152
  # unique name for specific version of rule
148
153
  sname = "#{rule_pfx}_#{ruleh['group_id']}_#{ruleh['created_dt'].to_f}"
149
154
 
150
155
  # is it a dev posting?
151
156
  if Mcfly.is_infinity(pt)
152
- max_dt = ruleh["classname"].constantize.order("created_dt DESC").
157
+ max_dt = ruleh['classname'].constantize.order('created_dt DESC').
153
158
  limit(1).pluck(:created_dt).first
154
159
 
155
160
  @@dengines_dt ||= max_dt
@@ -169,14 +174,13 @@ class Marty::RuleScriptSet < Delorean::AbstractContainer
169
174
 
170
175
  @@engines[[pt, sname]] = sset.parse_check(sname, get_code(ruleh))
171
176
  end
172
- rescue Delorean::ParseError => e
177
+ rescue Delorean::ParseError => e
173
178
  f = get_parse_error_field(ruleh, e)
174
179
  msg = e.message.capitalize
175
180
  raise "Error in rule '#{ruleh['name']}' field '#{f}': #{msg}"
176
- end
177
181
  end
178
182
 
179
183
  def self.indent(s)
180
- s.gsub(/^/, ' '*4)
184
+ s.gsub(/^/, ' ' * 4)
181
185
  end
182
186
  end