public
Description: Infinite Monkeywrench - A frameworks for collecting, peeling, and sharing delicious bananas of data.
Homepage: http://infinitemonkeywrench.org
Clone URL: git://github.com/infochimps/imw.git
imw / meta / imw.rb
100644 96 lines (83 sloc) 2.547 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#
# h2. imw/foo -- desc lib
#
# action:: desc action
#
# == About
#
# Author:: (Philip flip Kromer, Dhruv Bansal) for Infinite Monkeywrench Project (mailto:coders@infochimps.org)
# Copyright:: Copyright (c) 2008 infochimps.org
# License:: GPL 3.0
# Website:: http://infinitemonkeywrench.org/
#
 
# Standard libraries
require 'rubygems'
require 'logger'
require 'yaml'
# require 'fileutils'
require 'ostruct'
 
# Push this directory to front of ruby lib path
$:.unshift(File.dirname(__FILE__))
 
# Load gems (snippet stolen from active_warehouse gem)
unless Kernel.respond_to?(:gem)
  Kernel.send :alias_method, :gem, :require_gem
end
unless defined?(Rake)
  gem 'rake'
  require 'rake'
end
unless defined?(ActiveSupport)
  gem 'activesupport'
  require 'active_support'
end
unless defined?(ActiveRecord)
  # active_support has many warnings.
  old_verbosity = $VERBOSE; $VERBOSE = false
  gem 'activerecord'
  require 'active_record'
  $VERBOSE = old_verbosity
end
 
# Load imw files
require 'imw/utils/version'
require 'imw/utils/core_extensions'
 
module IMWConfig
  # load config files
  config_files = [
    File.join(File.dirname(__FILE__), '../etc/imw_main_config.yaml'),
    File.join(File.dirname(__FILE__), '../etc/imw_site_config.yaml'),
  ]
  Config = { }
  config_files.map{ |f| YAML.load(File.open(f)) }.each do |cfg|
    Config.deep_merge!(cfg) unless cfg.blank?
  end
  # Hold identifiers under this amount
  IDMaxlen = 80
end
 
# Home base for all activity
 
 
require 'imw/model' # collection, dataset, field, contributor, ...
require 'imw/workflow/imw_paths'
 
# Note the capitalization on the class name -- else it's a constant
class IMW < OpenStruct
  include IMWPaths
 
  #
  # define a pool to sit in the given category/subcategory/pool
  #
  def initialize (cat, subcat, pool, hsh = { })
    super(hsh)
    self.cat, self.subcat, self.pool = cat, subcat, pool
    self.init_paths(cat, subcat, pool)
  end
 
  #
  # Guess the pool path from the first defined among
  # * pool_path_in argument
  # * $pool environment variable
  # * otherwise, the current working directory
  #
  def IMW.new_from_env(pool_path_in=nil, hsh={})
    pool_path_in ||= ENV['pool'] || ENV['PWD']
    pool_path_grokd = IMWPaths.grok_path(pool_path_in)
    raise ArgumentError.new("Couldn't understand path #{pool_path_in}") if !pool_path_grokd
    self.new(* (pool_path_grokd.values_at(:cat, :subcat, :pool)+[hsh]) )
  end
end
 
# puts "#{File.basename(__FILE__)}: You wield your Infinite Monkeywrench. Formidable!"