Module: Norikra::UDF

Defined in:
lib/norikra/udf.rb

Defined Under Namespace

Classes: AggregationSingle, SingleRow

Class Method Summary collapse

Class Method Details

.listupObject



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/norikra/udf.rb', line 94

def self.listup
  return unless defined? Gem

  plugins = Gem.find_latest_files('norikra/udf/*.rb')
  plugins.each do |plugin|
    begin
      debug "plugin file found!", :file => plugin
      rbpath = plugin.dup
      4.times do
        rbpath = File.dirname( rbpath )
      end
      files = Dir.entries( rbpath )
      gemname = files.select{|f| f=~ /\.gemspec$/ }.first.sub(/\.gemspec$/, '')
      require gemname
      load plugin
    rescue => e
      warn "Failed to load norikra UDF plugin", :plugin => plugin.to_s, :error_class => e.class, :error => e.message
      e.backtrace.each do |t|
        warn "  " + t
      end
    end
  end

  known_consts = [:SingleRow, :AggregateSingle]
  udf_bases = [Norikra::UDF::SingleRow, Norikra::UDF::AggregationSingle]
  udfs = []
  self.constants.each do |c|
    next if known_consts.include?(c)

    klass = Norikra::UDF.const_get(c)
    if klass.is_a?(Class) && udf_bases.include?(klass.superclass)
      udfs.push(klass)
    elsif klass.is_a?(Module) && klass.respond_to?(:plugins)
      udfs.push(klass)
    end
  end
  udfs
end