Class: Datacaster::Runtimes::StructureCleaner

Inherits:
Base
  • Object
show all
Defined in:
lib/datacaster/runtimes/structure_cleaner.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#reserved_instance_variables

Instance Method Summary collapse

Methods inherited from Base

#Failure, #Success, #after_call!, #before_call!, call, #inspect, #method_missing, not_found!, #respond_to_missing?, send_to_parent, #to_s

Constructor Details

#initializeStructureCleaner

Returns a new instance of StructureCleaner.



6
7
8
9
10
11
12
13
14
# File 'lib/datacaster/runtimes/structure_cleaner.rb', line 6

def initialize(*)
  super
  @ignore = false
  @checked_schema = {}
  @should_check_stack = [false]
  @pointer_stack = [@checked_schema]

  @reserved_instance_variables += instance_variables
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Datacaster::Runtimes::Base

Instance Attribute Details

#checked_schemaObject

Returns the value of attribute checked_schema.



4
5
6
# File 'lib/datacaster/runtimes/structure_cleaner.rb', line 4

def checked_schema
  @checked_schema
end

Instance Method Details

#checked_key!(key) ⇒ Object

Array checked schema are the same as hash one, where instead of keys there are array indicies



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/datacaster/runtimes/structure_cleaner.rb', line 18

def checked_key!(key)
  if @ignore
    return yield if block_given?
    return
  end

  @pointer_stack.last[key] ||= {}
  @pointer_stack.push(@pointer_stack.last[key])
  @should_check_stack.push(false)
  result = yield if block_given?
  was_checked = @should_check_stack.pop
  @pointer_stack.pop
  @pointer_stack.last[key] = true unless was_checked
  result
end

#checked_schema!(schema) ⇒ Object

Notify current runtime that some child runtime has built schema, child runtime’s schema is passed as the argument



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/datacaster/runtimes/structure_cleaner.rb', line 45

def checked_schema!(schema)
  # Current runtime has marked its schema as checked unconditionally
  return if @pointer_stack[-1] == true

  # Child runtime marks its schema as checked unconditionally, so
  # current runtime should do as well
  if schema == true
    @pointer_stack[-1] = true
  # Child runtime's schema should be merged with current runtime's schema
  else
    will_check!
    @pointer_stack[-1].merge!(schema)
  end
end

#ignore_checks!(&block) ⇒ Object



60
61
62
63
64
65
# File 'lib/datacaster/runtimes/structure_cleaner.rb', line 60

def ignore_checks!(&block)
  @ignore = true
  result = yield
  @ignore = false
  result
end

#unchecked?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/datacaster/runtimes/structure_cleaner.rb', line 67

def unchecked?
  @should_check_stack == [false]
end

#will_check!Object



34
35
36
37
# File 'lib/datacaster/runtimes/structure_cleaner.rb', line 34

def will_check!
  return if @ignore
  @should_check_stack[-1] = true
end

#will_not_check!Object



39
40
41
# File 'lib/datacaster/runtimes/structure_cleaner.rb', line 39

def will_not_check!
  @should_check_stack[-1] = false
end