Sha256: c4d5678f2c1b9f60a5e4983049a3e73c80ea9758572f6c0f0602e43e4ea48513

Contents?: true

Size: 1.06 KB

Versions: 3

Compression:

Stored size: 1.06 KB

Contents

module Wukong
  module PigStructMethods
    module ClassMethods
      #
      # Pig type string --
      # the pig type strings for each sub-element.
      #
      def typify has_rsrc=nil
        vars_str = members.zip(mtypes).map do |attr, mtype|
          "%s: %s" % [attr, mtype.typify]
        end
        vars_str = ["rsrc: chararray"] + vars_str if has_rsrc
        "(#{vars_str.join(', ')})"
      end

      #
      #
      #
      def pig_load rel, *args
        Wukong::AndPig::PigVar.pig_load rel, self, *args
      end

      #
      # Returns type for a fieldspec
      #
      def field_type field
        case field
        when Symbol             then members_types[field]
        # when Array
        #   if field.length > 1   then members_types[field.first].field_type(field[1..-1])
        #   else                       field_type field.first
        #   end
        end
      end

    end
    def self.included base
      base.extend ClassMethods
    end
  end
end

Struct.class_eval do
  include Wukong::PigStructMethods
  def self.mtypes
    members
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
mrflip-wukong-0.1.0 lib/wukong/and_pig/pig_struct.rb
wukong-0.1.4 lib/wukong/and_pig/pig_struct.rb
wukong-0.1.1 lib/wukong/and_pig/pig_struct.rb