Class: Datacaster::Runtimes::Base

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

Direct Known Subclasses

I18n, ObjectContext, StructureCleaner, UserContext

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent = nil) ⇒ Base

Returns a new instance of Base.



25
26
27
28
29
30
31
# File 'lib/datacaster/runtimes/base.rb', line 25

def initialize(parent = nil)
  @parent = parent

  # We won't be setting any instance variables outside this
  # constructor, so we can proxy all the rest to the @object
  @reserved_instance_variables = Set.new(instance_variables + [:@reserved_instance_variables])
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



33
34
35
# File 'lib/datacaster/runtimes/base.rb', line 33

def method_missing(m, *args, &block)
  self.class.send_to_parent(self, m, *args, &block)
end

Instance Attribute Details

#reserved_instance_variablesObject (readonly)

Returns the value of attribute reserved_instance_variables.



6
7
8
# File 'lib/datacaster/runtimes/base.rb', line 6

def reserved_instance_variables
  @reserved_instance_variables
end

Class Method Details

.call(r, proc, *args) ⇒ Object



8
9
10
11
12
13
# File 'lib/datacaster/runtimes/base.rb', line 8

def self.call(r, proc, *args)
  r.before_call!(r)
  result = r.instance_exec(*args, &proc)
  r.after_call!(r)
  result
end

.not_found!(m) ⇒ Object

Raises:

  • (NoMethodError)


21
22
23
# File 'lib/datacaster/runtimes/base.rb', line 21

def self.not_found!(m)
  raise NoMethodError.new("Method #{m.inspect} is not available in current runtime context")
end

.send_to_parent(r, m, *args, &block) ⇒ Object



15
16
17
18
19
# File 'lib/datacaster/runtimes/base.rb', line 15

def self.send_to_parent(r, m, *args, &block)
  parent = r.instance_variable_get(:@parent)
  not_found!(m) if parent.nil?
  call(parent, -> { public_send(m, *args, &block) })
end

Instance Method Details

#after_call!(sender) ⇒ Object



41
42
43
# File 'lib/datacaster/runtimes/base.rb', line 41

def after_call!(sender)
  @parent.after_call!(sender) if @parent
end

#before_call!(sender) ⇒ Object



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

def before_call!(sender)
  @parent.before_call!(sender) if @parent
end

#Failure(v) ⇒ Object



61
62
63
# File 'lib/datacaster/runtimes/base.rb', line 61

def Failure(v)
  Datacaster.ErrorResult(v)
end

#inspectObject



49
50
51
# File 'lib/datacaster/runtimes/base.rb', line 49

def inspect
  "#<#{self.class.name} parent: #{@parent.inspect}>"
end

#respond_to_missing?(m, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/datacaster/runtimes/base.rb', line 37

def respond_to_missing?(m, include_private = false)
  !@parent.nil? && @parent.respond_to?(m, include_private)
end

#Success(v) ⇒ Object



57
58
59
# File 'lib/datacaster/runtimes/base.rb', line 57

def Success(v)
  Datacaster.ValidResult(v)
end

#to_sObject



53
54
55
# File 'lib/datacaster/runtimes/base.rb', line 53

def to_s
  inspect
end