configura 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README.markdown +40 -0
  2. data/Rakefile +13 -0
  3. data/VERSION +1 -0
  4. data/lib/configura.rb +68 -0
  5. metadata +58 -0
@@ -0,0 +1,40 @@
1
+ Dead simple configuration management for simple scripts
2
+ =======================================================
3
+
4
+ Honestly, it doesn't do a lot, but it does let you avoid putting passwords and the like in your scripts.
5
+
6
+ Install with
7
+
8
+ gem install configura
9
+
10
+ For example, if you were writing a twitter script, you could do:
11
+
12
+ config = Configura.new
13
+ httpauth = Twitter::HTTPAuth.new(config['twitter.email'], config['twitter.password'])
14
+ base = Twitter::Base.new(httpauth)
15
+
16
+ If you're running at the terminal, you'll be prompted to enter missing values - which will then be saved to $HOME/.configura. Otherwise a missing value will cause an exception to be raised.
17
+
18
+
19
+ MIT License
20
+ ===========
21
+
22
+ (c) Ben Griffiths 2009
23
+
24
+ Permission is hereby granted, free of charge, to any person obtaining a copy
25
+ of this software and associated documentation files (the "Software"), to deal
26
+ in the Software without restriction, including without limitation the rights
27
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
28
+ copies of the Software, and to permit persons to whom the Software is
29
+ furnished to do so, subject to the following conditions:
30
+
31
+ The above copyright notice and this permission notice shall be included in
32
+ all copies or substantial portions of the Software.
33
+
34
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
35
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
36
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
37
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
38
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
39
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
40
+ THE SOFTWARE.
@@ -0,0 +1,13 @@
1
+ begin
2
+ require 'jeweler'
3
+ Jeweler::Tasks.new do |gemspec|
4
+ gemspec.name = "configura"
5
+ gemspec.summary = "Simple config management for simple short-order scripts"
6
+ gemspec.email = "configura@techbelly.com"
7
+ gemspec.homepage = "http://github.com/techbelly/configura"
8
+ gemspec.authors = ["Ben Griffiths"]
9
+ end
10
+ Jeweler::GemcutterTasks.new
11
+ rescue LoadError
12
+ puts "Jeweler not available. Install it with: sudo gem install jeweler"
13
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,68 @@
1
+ class Configura
2
+
3
+ class AskForMissingValue
4
+ def seek(key)
5
+ value = ""
6
+ begin
7
+ print "Please enter value for #{key}: "
8
+ value = gets.chomp
9
+ end while value.empty?
10
+ value
11
+ end
12
+ end
13
+
14
+ class FailWhenMissingValue
15
+ def seek(key)
16
+ raise "You must give a value for #{key}."
17
+ end
18
+ end
19
+
20
+ def initialize()
21
+ @file = "#{ENV['HOME']}/.configura"
22
+ ensure_file_exists
23
+ @missing_value_strategy = $stdout.tty? ? AskForMissingValue.new : FailWhenMissingValue.new
24
+ load
25
+ end
26
+
27
+ def ensure_file_exists(file)
28
+ unless File.exists? file
29
+ @config = {}
30
+ save
31
+ end
32
+ end
33
+
34
+ def load
35
+ @config ||= YAML::load(open(file))
36
+ self
37
+ end
38
+
39
+ def [](key)
40
+ load
41
+ if @config[key].nil?
42
+ @config[key] = @missing_value_strategy.seek(key)
43
+ save
44
+ end
45
+ @config[key]
46
+ end
47
+
48
+ def []=(key, value)
49
+ @config[key] = value
50
+ end
51
+
52
+ def delete(*keys)
53
+ keys.each { |key| @config.delete(key) }
54
+ save
55
+ self
56
+ end
57
+
58
+ def update(c={})
59
+ @config.merge!(c)
60
+ save
61
+ self
62
+ end
63
+
64
+ def save
65
+ File.open(file, 'w') { |f| f.write(YAML.dump(@config)) }
66
+ self
67
+ end
68
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: configura
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ben Griffiths
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-14 00:00:00 +00:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: configura@techbelly.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.markdown
24
+ files:
25
+ - README.markdown
26
+ - Rakefile
27
+ - VERSION
28
+ - lib/configura.rb
29
+ has_rdoc: true
30
+ homepage: http://github.com/techbelly/configura
31
+ licenses: []
32
+
33
+ post_install_message:
34
+ rdoc_options:
35
+ - --charset=UTF-8
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: "0"
43
+ version:
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ version:
50
+ requirements: []
51
+
52
+ rubyforge_project:
53
+ rubygems_version: 1.3.5
54
+ signing_key:
55
+ specification_version: 3
56
+ summary: Simple config management for simple short-order scripts
57
+ test_files: []
58
+