Sha256: 18f89510ee5a0e2610c0f03c32c8106c35926c722df677f7089afe7c0b01b454

Contents?: true

Size: 1.45 KB

Versions: 1

Compression:

Stored size: 1.45 KB

Contents

module DataModule

  attr_accessor :sharedir, :rakefile, :pkg_module
  def self.extended(base)
    if defined? base::PKG and base::PKG
      base.pkg_module = base::PKG
    else
      base.pkg_module = Rbbt
    end

    base.sharedir = PKGData.get_caller_sharedir 
    
    Dir.glob(File.join(base.sharedir, 'install', base.to_s, '**','Rakefile')).each do |rakefile|
      RakeHelper.files(rakefile).each do |file|
        base.pkg_module.claim file, 
          rakefile.sub(/^#{Regexp.quote File.join(base.sharedir)}\/?/,''), 
          File.dirname(rakefile).sub(/^#{Regexp.quote File.join(base.sharedir, 'install')}\/?/,'')
      end
    end
  end

  module WithKey
    def klass=(klass)
      @klass = klass
    end
   
    def klass
      @klass
    end

    def key=(key)
      @key = key
    end

    def key
      @key
    end

    def method_missing(name, *args)
      if key
        klass.send(name, key, *args)
      else
        klass.send(name, *args)
      end
    end
  end

  def with_key(key)
    klass = self
    o = Object.new
    o.extend WithKey
    o.klass = self
    o.key = key
    o
  end

  alias old_method_missing method_missing
  def method_missing(name, *args, &block)
    begin
      if args.any?
        pkg_module.files[self.to_s][args.first][name] 
      else
        pkg_module.files[self.to_s][name] 
      end
    rescue
      Log.debug $!.message
      Log.debug $!.backtrace * "\n"
      old_method_missing name, *args, &block
    end
  end


end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rbbt-util-1.2.1 lib/rbbt/util/data_module.rb