Module: Alf::Support::TupleScope::OwnMethods

Defined in:
lib/alf/support/tuple_scope.rb

Instance Method Summary collapse

Instance Method Details

#[](what) ⇒ Object


54
55
56
# File 'lib/alf/support/tuple_scope.rb', line 54

def [](what)
  @tuple[what]
end

#__build(tuple) ⇒ Object

Builds this scope with a tuple.

This method should be called only once and installs instance methods on the scope with keys of tuple.


45
46
47
48
49
50
51
52
# File 'lib/alf/support/tuple_scope.rb', line 45

def __build(tuple)
  tuple.keys.each do |k|
    (class << self; self; end).send(:define_method, k) do
      @tuple[k]
    end
  end
  self
end

#__set_tuple(tuple) ⇒ TupleScope

Sets the next tuple to use.

On first call, this method installs the scope as a side effect unless a tuple has already been provided at construction.


35
36
37
38
39
# File 'lib/alf/support/tuple_scope.rb', line 35

def __set_tuple(tuple)
  __build(tuple) if @tuple.nil?
  @tuple = tuple
  self
end

#inspectObject


70
71
72
# File 'lib/alf/support/tuple_scope.rb', line 70

def inspect
  @tuple.inspect
end

#respond_to?(name) ⇒ Boolean

Returns true if the decorated tuple has `name` as key.


23
24
25
26
# File 'lib/alf/support/tuple_scope.rb', line 23

def respond_to?(name)
  return true if @tuple && @tuple.has_key?(name)
  super
end

#to_relationObject


62
63
64
# File 'lib/alf/support/tuple_scope.rb', line 62

def to_relation
  Relation(@tuple)
end

#to_sObject


66
67
68
# File 'lib/alf/support/tuple_scope.rb', line 66

def to_s
  @tuple.to_s
end

#to_tupleObject


58
59
60
# File 'lib/alf/support/tuple_scope.rb', line 58

def to_tuple
  Tuple(@tuple)
end