Class: DataShift::NodeContext

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/datashift/node_context.rb

Direct Known Subclasses

EmptyContext

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#logdir, #logdir=, #logger, #verbose

Constructor Details

#initialize(doc_context, method_binding, row_idx, data) ⇒ NodeContext

Returns a new instance of NodeContext.



23
24
25
26
27
28
29
30
# File 'lib/datashift/node_context.rb', line 23

def initialize(doc_context, method_binding, row_idx, data)
  @doc_context = doc_context
  @method_binding = method_binding
  @row_index = row_idx
  @data = data

  @populator = PopulatorFactory.get_populator(method_binding)
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



21
22
23
# File 'lib/datashift/node_context.rb', line 21

def data
  @data
end

#doc_contextObject

Returns the value of attribute doc_context.



17
18
19
# File 'lib/datashift/node_context.rb', line 17

def doc_context
  @doc_context
end

#method_bindingObject

Returns the value of attribute method_binding.



17
18
19
# File 'lib/datashift/node_context.rb', line 17

def method_binding
  @method_binding
end

#populatorObject

Returns the value of attribute populator.



19
20
21
# File 'lib/datashift/node_context.rb', line 19

def populator
  @populator
end

#row_indexObject

Returns the value of attribute row_index.



17
18
19
# File 'lib/datashift/node_context.rb', line 17

def row_index
  @row_index
end

Instance Method Details

#contains_data?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/datashift/node_context.rb', line 34

def contains_data?
  !(data.nil? || data.to_s.empty?)
end

#next_update?Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
# File 'lib/datashift/node_context.rb', line 38

def next_update?
  false # for now create only
  # TODO : Support UPDATES
  # next = ProcessingRules.next_action(method_binding )
  # next == :update
end

#processObject



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/datashift/node_context.rb', line 45

def process
  populator.prepare_and_assign(self, doc_context.load_object, data)
rescue StandardError => x
  failed = FailureData.new( doc_context.load_object, self, x.message)

  failed.error_messages <<  "Failed to process node : #{method_binding.pp}"

  doc_context.progress_monitor.failure(failed)

  logger.error("#{x.backtrace.first} : #{x.message}")
  raise x
end