app_config 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +10 -2
- data/lib/app_config.rb +1 -11
- data/lib/app_config/base.rb +7 -2
- data/lib/app_config/error.rb +11 -0
- data/lib/app_config/storage.rb +4 -2
- data/lib/app_config/storage/base_storage.rb +13 -0
- data/lib/app_config/storage/memory.rb +11 -0
- data/lib/app_config/storage/sqlite.rb +8 -7
- data/lib/app_config/storage/yaml.rb +3 -7
- metadata +7 -13
data/README
CHANGED
@@ -9,6 +9,13 @@ An easy to use, customizable library to easily store and retrieve application
|
|
9
9
|
Usage is simple. Just pass either a hash of options, or a block, to
|
10
10
|
AppConfig.setup. See AppConfig::Base for a list of valid storage methods.
|
11
11
|
|
12
|
+
As of version 0.4.1, if the <tt>:storage_method</tt> is not set, AppConfig
|
13
|
+
will act pretty much just like a normal Hash:
|
14
|
+
|
15
|
+
AppConfig.setup(:email => 'admin@example.com')
|
16
|
+
AppConfig[:email] # => 'admin@example.com'
|
17
|
+
|
18
|
+
|
12
19
|
== AppConfig::Storage::YAML
|
13
20
|
|
14
21
|
Given this YAML file:
|
@@ -35,15 +42,16 @@ Use it like so:
|
|
35
42
|
AppConfig[:api_name] # => 'Supr Webz 2.0'
|
36
43
|
AppConfig[:api_key] # => 'SUPERAWESOMESERVICE'
|
37
44
|
|
45
|
+
|
38
46
|
== AppConfig::Storage::Sqlite
|
39
47
|
|
40
48
|
AppConfig.setup do |config|
|
41
49
|
config[:storage_method] = :sqlite
|
50
|
+
config[:table] = 'app_config' # defaults to 'app_config'
|
51
|
+
|
42
52
|
config[:database] = '/path/to/database.sqlite3'
|
43
53
|
# ..or..
|
44
54
|
config[:uri] = 'sqlite://path/to/database.sqlite3'
|
45
|
-
|
46
|
-
config[:table] = 'app_config' # defaults to 'app_config'
|
47
55
|
end
|
48
56
|
|
49
57
|
AppConfig[:column] # => 'value'
|
data/lib/app_config.rb
CHANGED
@@ -1,20 +1,10 @@
|
|
1
1
|
$LOAD_PATH.unshift File.dirname(__FILE__)
|
2
2
|
|
3
|
-
# TODO: Only load deps if needed (no gems unless required).
|
4
|
-
dependencies = %w{ sqlite3 yaml uri }
|
5
|
-
|
6
|
-
begin
|
7
|
-
dependencies.each { |lib| require lib }
|
8
|
-
rescue LoadError
|
9
|
-
require 'rubygems'
|
10
|
-
dependencies.each { |lib| require lib }
|
11
|
-
end
|
12
|
-
|
13
3
|
# AppConfig stuff.
|
14
4
|
require 'core_ext/hashish'
|
15
5
|
|
16
6
|
module AppConfig
|
17
|
-
VERSION = '0.4.
|
7
|
+
VERSION = '0.4.1'
|
18
8
|
|
19
9
|
autoload :Base, 'app_config/base'
|
20
10
|
autoload :Error, 'app_config/error'
|
data/lib/app_config/base.rb
CHANGED
@@ -1,18 +1,21 @@
|
|
1
1
|
module AppConfig
|
2
2
|
|
3
|
+
require 'uri'
|
4
|
+
|
3
5
|
# The Base storage class.
|
4
6
|
# Acts as a wrapper for the different storage methods.
|
5
7
|
#
|
6
8
|
# See each storage method's documentation for their specific options.
|
7
9
|
#
|
8
10
|
# Valid storage methods:
|
11
|
+
# * :memory (AppConfig::Storage::Memory)
|
9
12
|
# * :sqlite (AppConfig::Storage::Sqlite)
|
10
13
|
# * :yaml (AppConfig::Storage::YAML)
|
11
14
|
class Base
|
12
15
|
|
13
|
-
# TODO:
|
16
|
+
# TODO: All these DEFAULTS constants are kinda annoying.
|
14
17
|
DEFAULTS = {
|
15
|
-
:storage_method => :
|
18
|
+
:storage_method => :memory,
|
16
19
|
}
|
17
20
|
|
18
21
|
# Accepts either a hash of +options+ or a block (which overrides
|
@@ -64,6 +67,8 @@ module AppConfig
|
|
64
67
|
# TODO: Maybe purge AppConfig options (ie, those not related to the user-end).
|
65
68
|
def initialize_storage
|
66
69
|
case @options[:storage_method]
|
70
|
+
when :memory
|
71
|
+
AppConfig::Storage::Memory.load(@options)
|
67
72
|
when :sqlite
|
68
73
|
AppConfig::Storage::Sqlite.load(@options)
|
69
74
|
when :yaml
|
data/lib/app_config/storage.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module AppConfig
|
2
2
|
module Storage
|
3
|
-
autoload :
|
4
|
-
autoload :
|
3
|
+
autoload :BaseStorage, 'app_config/storage/base_storage'
|
4
|
+
autoload :Memory, 'app_config/storage/memory'
|
5
|
+
autoload :Sqlite, 'app_config/storage/sqlite'
|
6
|
+
autoload :YAML, 'app_config/storage/yaml'
|
5
7
|
end
|
6
8
|
end
|
@@ -1,9 +1,15 @@
|
|
1
1
|
module AppConfig
|
2
2
|
module Storage
|
3
3
|
|
4
|
+
begin
|
5
|
+
require 'sqlite3'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'sqlite3'
|
9
|
+
end
|
10
|
+
|
4
11
|
# SQLite3 storage method.
|
5
|
-
class Sqlite
|
6
|
-
attr_accessor :data
|
12
|
+
class Sqlite < BaseStorage
|
7
13
|
|
8
14
|
DEFAULTS = {
|
9
15
|
:database => File.expand_path(File.join(ENV['HOME'], '.app_config.sqlite3')),
|
@@ -20,11 +26,6 @@ module AppConfig
|
|
20
26
|
@data = load_from_database
|
21
27
|
end
|
22
28
|
|
23
|
-
# Creates a new Sqlite storage with the given +path+ and returns the data.
|
24
|
-
def self.load(path)
|
25
|
-
new(path).data
|
26
|
-
end
|
27
|
-
|
28
29
|
private
|
29
30
|
|
30
31
|
# Returns a Hashish that looks something like {:column => value}.
|
@@ -1,9 +1,10 @@
|
|
1
1
|
module AppConfig
|
2
2
|
module Storage
|
3
3
|
|
4
|
+
require 'yaml'
|
5
|
+
|
4
6
|
# YAML storage method.
|
5
|
-
class YAML
|
6
|
-
attr_reader :data
|
7
|
+
class YAML < BaseStorage
|
7
8
|
|
8
9
|
DEFAULTS = {
|
9
10
|
:path => File.expand_path(File.join(ENV['HOME'], '.app_config.yml'))
|
@@ -19,11 +20,6 @@ module AppConfig
|
|
19
20
|
@data = Hashish.new(::YAML.load_file(path))
|
20
21
|
end
|
21
22
|
|
22
|
-
# Creates a new YAML storage with the given +path+ and returns the data.
|
23
|
-
def self.load(path)
|
24
|
-
new(path).data
|
25
|
-
end
|
26
|
-
|
27
23
|
end # YAML
|
28
24
|
end # Storage
|
29
25
|
end # AppConfig
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: app_config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dale Campbell
|
@@ -9,19 +9,10 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-10-
|
12
|
+
date: 2009-10-25 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
16
|
-
name: sqlite3-ruby
|
17
|
-
type: :runtime
|
18
|
-
version_requirement:
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: "0"
|
24
|
-
version:
|
14
|
+
dependencies: []
|
15
|
+
|
25
16
|
description: An easy to use, customizable library to easily store and retrieve application configuration.
|
26
17
|
email:
|
27
18
|
- oshuma@gmail.com
|
@@ -36,7 +27,10 @@ files:
|
|
36
27
|
- README
|
37
28
|
- lib/app_config.rb
|
38
29
|
- lib/app_config/base.rb
|
30
|
+
- lib/app_config/error.rb
|
39
31
|
- lib/app_config/storage.rb
|
32
|
+
- lib/app_config/storage/base_storage.rb
|
33
|
+
- lib/app_config/storage/memory.rb
|
40
34
|
- lib/app_config/storage/sqlite.rb
|
41
35
|
- lib/app_config/storage/yaml.rb
|
42
36
|
- lib/core_ext/hashish.rb
|