config_file 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in config_file.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Tal Atlas
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # ConfigFile
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'config_file'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install config_file
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/config_file/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Tal Atlas"]
6
+ gem.email = ["me@tal.by"]
7
+ gem.description = %q{Gem for quickly reading from config files}
8
+ gem.summary = %q{Gem for quickly reading from config files}
9
+ gem.homepage = "http://github.com/talby/config_file"
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "config_file"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = ConfigFile::VERSION
17
+
18
+ gem.add_dependency("blankslate")
19
+ end
@@ -0,0 +1,91 @@
1
+ require "config_file/version"
2
+ require 'yaml'
3
+ require 'pathname'
4
+ require 'erb'
5
+
6
+ class ConfigFile < BlankSlate
7
+ class UnknownConfigFile < ArgumentError; end
8
+ class UnknownKey < StandardError; end
9
+ attr_writer :raise_on_missing_key
10
+
11
+ def initialize file
12
+ @file = file
13
+ @raise_on_missing_key = false
14
+ end
15
+
16
+ def method_missing(key,*args)
17
+ @data = nil if ConfigFile.dev?
18
+ if data.has_key?(key)
19
+ data[key]
20
+ elsif data.has_key?(key.to_s)
21
+ data[key.to_s]
22
+ else
23
+ @raise_on_missing_key ? raise(UnknownKey, "#{key} couldn't be found in #{@file}") : nil
24
+ end
25
+ end
26
+
27
+ def __data__
28
+ @data ||= begin
29
+ d = nil
30
+ File.open(@file) do |f|
31
+ d = YAML.load ERB.new(f.read).result
32
+ end
33
+ d = d[ConfigFile.env] if d.has_key? ConfigFile.env
34
+ d
35
+ end
36
+ end
37
+ alias data __data__
38
+
39
+ ALL = {}
40
+ class << self
41
+ attr_writer :env, :root, :config_dirs
42
+ def env
43
+ @env ||= case
44
+ when defined?(ENVIRONMENT)
45
+ ENVIRONMENT
46
+ when defined?(Rails)
47
+ Rails.env
48
+ else
49
+ ENV['RACK_ENV'] || ENV['RAILS_ENV'] || ENV['ENVIRONMENT']
50
+ end
51
+ end
52
+
53
+ def root
54
+ @root ||= case
55
+ when defined?(Rails)
56
+ Rails.root
57
+ else
58
+ Pathname.new(File.expand_path('.'))
59
+ end
60
+ end
61
+
62
+ def dev?
63
+ @dev ||= env == 'development'
64
+ end
65
+
66
+ def config_dirs
67
+ @config_dirs ||= %w{config .}
68
+ end
69
+
70
+ def method_missing(name,*args)
71
+ ALL[name] ||= if file = find_file(name)
72
+ new(file)
73
+ else
74
+ raise UnknownConfigFile, "couldn't find file at 'config/#{name}.yml'"
75
+ end
76
+ end
77
+
78
+ private
79
+
80
+ def find_file name
81
+ files = []
82
+ config_dirs.each do |dir|
83
+ files << root+"#{dir}/#{name}.yml"
84
+ files << root+"#{dir}/#{name}.yaml"
85
+ end
86
+ files.find do |f|
87
+ File.exist?(f)
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,5 @@
1
+ require 'blankslate'
2
+
3
+ class ConfigFile < BlankSlate
4
+ VERSION = "0.0.1"
5
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: config_file
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tal Atlas
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-09 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: blankslate
16
+ requirement: &70136086881140 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70136086881140
25
+ description: Gem for quickly reading from config files
26
+ email:
27
+ - me@tal.by
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - config_file.gemspec
38
+ - lib/config_file.rb
39
+ - lib/config_file/version.rb
40
+ homepage: http://github.com/talby/config_file
41
+ licenses: []
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 1.8.10
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: Gem for quickly reading from config files
64
+ test_files: []