Sha256: 93ad6ff8052f42cf118aa8fd71a5cacb6a65d54e5c8b15704b5173d230f71e0d

Contents?: true

Size: 1000 Bytes

Versions: 1

Compression:

Stored size: 1000 Bytes

Contents

# encoding: utf-8

module Piglet
  module Field
    class Reference # :nodoc:
      include Field
    
      def initialize(name, relation=nil, options=nil)
        options ||= {}
        @name, @parent = name, relation
        @explicit_ancestry = options[:explicit_ancestry] || false
        @type = options[:type]
        @predecessors = [relation] unless relation.nil?
      end
    
      def simple?
        true
      end

      def method_missing(name, *args)
        if name.to_s =~ /^\w+$/ && args.empty?
          field(name)
        else
          super
        end
      end
    
      def [](n)
        field("\$#{n}")
      end
    
      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
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
piglet-0.3.0 lib/piglet/field/reference.rb