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

#ignore_checks!(&block) ⇒ Object



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

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

#unchecked?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/datacaster/runtimes/structure_cleaner.rb', line 45

def unchecked?
  @should_check_stack == [false]
end

#will_check!Object



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

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