factor 0.5.10 → 0.5.12

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.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- factor (0.5.10)
4
+ factor (0.5.12)
5
5
  colored (~> 1.2)
6
6
  commander (~> 4.2.1)
7
7
  configatron (~> 4.2.0)
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Primary Factor.io module
4
4
  module Factor
5
- VERSION = '0.5.10'
5
+ VERSION = '0.5.12'
6
6
  end
data/lib/runtime.rb CHANGED
@@ -143,6 +143,43 @@ module Factor
143
143
 
144
144
  private
145
145
 
146
+ class DeepStruct < OpenStruct
147
+ def initialize(hash=nil)
148
+ @table = {}
149
+ @hash_table = {}
150
+
151
+ if hash
152
+ hash.each do |k,v|
153
+ @table[k.to_sym] = (v.is_a?(Hash) ? self.class.new(v) : v)
154
+ @hash_table[k.to_sym] = v
155
+
156
+ new_ostruct_member(k)
157
+ end
158
+ end
159
+ end
160
+
161
+ def to_h
162
+ @hash_table
163
+ end
164
+
165
+ def [](idx)
166
+ hash = marshal_dump
167
+ hash[idx.to_sym]
168
+ end
169
+ end
170
+
171
+ def simple_object_convert(item)
172
+ if item.is_a?(Hash)
173
+ DeepStruct.new(item)
174
+ elsif item.is_a?(Array)
175
+ item.map do |i|
176
+ simple_object_convert(i)
177
+ end
178
+ else
179
+ item
180
+ end
181
+ end
182
+
146
183
  def flat_hash(h,f=[],g={})
147
184
  return g.update({ f=>h }) unless h.is_a? Hash
148
185
  h.each { |k,r| flat_hash(r,f+[k],g) }
@@ -161,17 +198,8 @@ module Factor
161
198
  end
162
199
 
163
200
  def error_handle_call(listener_response, &block)
164
- payload = if listener_response['payload'].is_a?(Hash)
165
- OpenStruct.new(listener_response['payload'])
166
- elsif listener_response['payload'].is_a?(Array)
167
- listener_response['payload'].map do |i|
168
- i.is_a?(Hash) ? OpenStruct.new(i) : i
169
- end
170
- else
171
- listener_response['payload']
172
- end
173
- block.call(payload) if block
174
-
201
+ content = simple_object_convert(listener_response['payload'])
202
+ block.call(content) if block
175
203
  rescue => ex
176
204
  error "Error in workflow definition: #{ex.message}"
177
205
  ex.backtrace.each do |line|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.10
4
+ version: 0.5.12
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: