Class: Piglet::Field::Reference
- Inherits:
-
Object
- Object
- Piglet::Field::Reference
- Includes:
- Field
- Defined in:
- lib/piglet/field/reference.rb
Overview
:nodoc:
Constant Summary
Constants included from Field
Field::FUNCTIONS, Field::SYMBOLIC_OPERATORS
Instance Attribute Summary
Attributes included from Field
Instance Method Summary collapse
- #[](n) ⇒ Object
-
#initialize(name, relation = nil, options = nil) ⇒ Reference
constructor
A new instance of Reference.
- #method_missing(name, *args) ⇒ Object
- #simple? ⇒ Boolean
- #to_s(inner = false) ⇒ Object
Methods included from Field
#and, #as, #cast, #diff, #distinct, #empty?, #field, #field_alias, #filter, #flatten, #generate_field_alias, #get, #limit, #matches, #ne, #neg, #not, #not_null?, #null?, #or, #order, #sample
Constructor Details
#initialize(name, relation = nil, options = nil) ⇒ Reference
Returns a new instance of Reference.
8 9 10 11 12 13 14 |
# File 'lib/piglet/field/reference.rb', line 8 def initialize(name, relation=nil, =nil) ||= {} @name, @parent = name, relation @explicit_ancestry = [:explicit_ancestry] || false @type = [:type] @predecessors = [relation] unless relation.nil? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/piglet/field/reference.rb', line 20 def method_missing(name, *args) if name.to_s =~ /^\w+$/ && args.empty? field(name) else super end end |
Instance Method Details
#[](n) ⇒ Object
28 29 30 |
# File 'lib/piglet/field/reference.rb', line 28 def [](n) field("\$#{n}") end |
#simple? ⇒ Boolean
16 17 18 |
# File 'lib/piglet/field/reference.rb', line 16 def simple? true end |
#to_s(inner = false) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/piglet/field/reference.rb', line 32 def to_s(inner=false) if @explicit_ancestry if @parent.respond_to?(:alias) "#{@parent.alias}.#{@name.to_s}" else expr = if inner then @parent.field_alias else @parent end "#{expr}.#{@name.to_s}" end else @name.to_s end end |