Class: Piglet::Field::Reference
- Inherits:
-
Object
- Object
- Piglet::Field::Reference
show all
- Includes:
- Field
- Defined in:
- lib/piglet/field/reference.rb
Overview
Constant Summary
Constants included
from Field
Field::FUNCTIONS, Field::SYMBOLIC_OPERATORS
Instance Attribute Summary
Attributes included from Field
#name, #type
Instance Method Summary
collapse
Methods included from Field
#and, #as, #cast, #diff, #empty?, #matches, #ne, #neg, #not, #not_null?, #null?, #or
Constructor Details
#initialize(name, relation = nil, options = nil) ⇒ Reference
8
9
10
11
12
13
|
# File 'lib/piglet/field/reference.rb', line 8
def initialize(name, relation=nil, options=nil)
options ||= {}
@name, @parent = name, relation
@explicit_ancestry = options[:explicit_ancestry] || false
@type = options[:type]
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
23
24
25
26
27
28
29
|
# File 'lib/piglet/field/reference.rb', line 23
def method_missing(name, *args)
if name.to_s =~ /^\w+$/ && args.empty?
field(name)
else
super
end
end
|
Instance Method Details
#[](n) ⇒ Object
31
32
33
|
# File 'lib/piglet/field/reference.rb', line 31
def [](n)
field("\$#{n}")
end
|
#field(name) ⇒ Object
19
20
21
|
# File 'lib/piglet/field/reference.rb', line 19
def field(name)
Reference.new(name, self, :explicit_ancestry => true)
end
|
#simple? ⇒ Boolean
15
16
17
|
# File 'lib/piglet/field/reference.rb', line 15
def simple?
true
end
|
#to_s ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/piglet/field/reference.rb', line 35
def to_s
if @explicit_ancestry
if @parent.respond_to?(:alias)
"#{@parent.alias}.#{@name.to_s}"
else
"#{@parent}.#{@name.to_s}"
end
else
@name.to_s
end
end
|