uber_config 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .idea/*
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in uber_config.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem 'test-unit'
8
+ end
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,83 @@
1
+ require "uber_config/version"
2
+
3
+ module UberConfig
4
+
5
+ # Load a config file from various system locations
6
+ def self.load(options={})
7
+
8
+ # First check for abt config
9
+ if defined? $abt_config
10
+ @config = $abt_config
11
+ return @config
12
+ end
13
+
14
+ dir = nil
15
+ if options[:dir]
16
+ dir = options[:dir]
17
+ if dir.is_a?(String)
18
+ dir = [dir]
19
+ end
20
+ end
21
+ file = "config.yml"
22
+ if options[:file]
23
+ file = options[:file]
24
+ end
25
+
26
+ p Kernel.caller
27
+ caller_file = caller[0][0...(caller[0].index(":in"))]
28
+ caller_file = caller_file[0...(caller_file.rindex(":"))]
29
+ p caller_file
30
+ caller_dir = File.dirname(caller_file)
31
+ p caller_dir
32
+ caller_dir_split = caller_dir.split("/")
33
+ p caller_dir_split
34
+ auto_dir_name = caller_dir_split.last
35
+ if auto_dir_name == "test"
36
+ caller_dir_split.pop
37
+ auto_dir_name = caller_dir_split.last
38
+ end
39
+ p auto_dir_name
40
+
41
+ # Now check near caller file
42
+ dir_and_file = dir.nil? ? [] : dir.dup
43
+ dir_and_file << file
44
+ p dir_and_file
45
+ location = File.join(dir_and_file)
46
+ p location
47
+ cf = File.expand_path(location, caller_dir)
48
+ puts "cf=" + cf.inspect
49
+ if File.exist?(cf)
50
+ @config = YAML::load_file(cf)
51
+ return @config
52
+ end
53
+
54
+ # and working directory
55
+ cf = File.expand_path(location)
56
+ puts "cf=" + cf.inspect
57
+ if File.exist?(cf)
58
+ @config = YAML::load_file(cf)
59
+ return @config
60
+ end
61
+
62
+ # Now check in Dropbox
63
+ dropbox_folders = ["~", "Dropbox", "configs"]
64
+ if dir
65
+ dropbox_folders = dropbox_folders + dir
66
+ else
67
+ dropbox_folders = dropbox_folders << auto_dir_name
68
+ end
69
+ dropbox_folders << file
70
+ cf = File.expand_path(File.join(dropbox_folders))
71
+ puts "cf=" + cf.inspect
72
+ if File.exist?(cf)
73
+ @config = YAML::load_file(cf)
74
+ return @config
75
+ end
76
+
77
+
78
+
79
+ # couldn't find it
80
+ return nil
81
+
82
+ end
83
+ end
@@ -0,0 +1,3 @@
1
+ module UberConfig
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,12 @@
1
+ gem 'test-unit'
2
+ require 'test/unit'
3
+ require_relative '../lib/uber_config'
4
+
5
+ class TestUberConfig < Test::Unit::TestCase
6
+
7
+ def test_loading
8
+ @config = UberConfig.load
9
+ p @config
10
+ end
11
+
12
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "uber_config/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "uber_config"
7
+ s.version = UberConfig::VERSION
8
+ s.authors = ["Travis Reeder"]
9
+ s.email = ["treeder@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Loads configs from common locations.}
12
+ s.description = %q{Loads configs from common locations.}
13
+
14
+ s.rubyforge_project = "uber_config"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+ end
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: uber_config
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Travis Reeder
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-03 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Loads configs from common locations.
15
+ email:
16
+ - treeder@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - Rakefile
24
+ - lib/uber_config.rb
25
+ - lib/uber_config/version.rb
26
+ - test/test_uber_config.rb
27
+ - uber_config.gemspec
28
+ homepage: ''
29
+ licenses: []
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubyforge_project: uber_config
48
+ rubygems_version: 1.8.21
49
+ signing_key:
50
+ specification_version: 3
51
+ summary: Loads configs from common locations.
52
+ test_files: []