simply_configurable 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +6 -0
- data/LICENSE.txt +7 -0
- data/README.rdoc +45 -0
- data/lib/simply_configurable/version.rb +3 -0
- data/lib/simply_configurable.rb +29 -0
- metadata +86 -0
data/CHANGELOG.rdoc
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2012 RevPAR Collective, Inc.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
= Simply Configurable
|
2
|
+
|
3
|
+
Makes it simple to set arbitrary config key/value pairs on a class.
|
4
|
+
|
5
|
+
== Synopsis:
|
6
|
+
|
7
|
+
require 'simply_configurable'
|
8
|
+
|
9
|
+
class Foo
|
10
|
+
|
11
|
+
include SimplyConfigurable
|
12
|
+
|
13
|
+
config :color => 'red'
|
14
|
+
config :style => 'awesome'
|
15
|
+
|
16
|
+
def style
|
17
|
+
puts "my style is #{config[:style]}"
|
18
|
+
end
|
19
|
+
|
20
|
+
class << self
|
21
|
+
def color
|
22
|
+
puts "my color is #{config['color']}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
Foo.color # prints 'my color is red'
|
29
|
+
foo = Foo.new
|
30
|
+
foo.style # prints 'my style is awesome'
|
31
|
+
|
32
|
+
Foo.config # returns { 'color' => 'red', 'style' => 'awesome' }
|
33
|
+
Foo.config[:color] # returns 'red'
|
34
|
+
|
35
|
+
Foo.config :color => 'green'
|
36
|
+
Foo.config['color'] # returns 'green'
|
37
|
+
|
38
|
+
== Class and Instance Access
|
39
|
+
|
40
|
+
The #config method is defined on both the class and its instances, so it may be simply called from either context.
|
41
|
+
|
42
|
+
== Hash Access
|
43
|
+
|
44
|
+
This library uses the HashWithIndifferentAccess class of the ActiveSupport library, allowing you to access/set config values by either symbol or string.
|
45
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'active_support/hash_with_indifferent_access'
|
2
|
+
|
3
|
+
module SimplyConfigurable
|
4
|
+
|
5
|
+
def self.included(klass)
|
6
|
+
klass.extend(ClassMethods)
|
7
|
+
end
|
8
|
+
|
9
|
+
def config
|
10
|
+
self.class.config
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
module ClassMethods
|
16
|
+
|
17
|
+
def config(options = {})
|
18
|
+
@config ||= HashWithIndifferentAccess.new({})
|
19
|
+
|
20
|
+
if options
|
21
|
+
@config.merge!(options || {})
|
22
|
+
end
|
23
|
+
|
24
|
+
@config
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simply_configurable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- David Dawson
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-04-12 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
22
|
+
none: false
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
hash: 7
|
27
|
+
segments:
|
28
|
+
- 3
|
29
|
+
- 0
|
30
|
+
version: "3.0"
|
31
|
+
version_requirements: *id001
|
32
|
+
name: activesupport
|
33
|
+
prerelease: false
|
34
|
+
type: :runtime
|
35
|
+
description: Makes it simple to set arbitrary config key/value pairs on a class.
|
36
|
+
email: daws23@gmail.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- README.rdoc
|
43
|
+
- CHANGELOG.rdoc
|
44
|
+
- LICENSE.txt
|
45
|
+
files:
|
46
|
+
- lib/simply_configurable/version.rb
|
47
|
+
- lib/simply_configurable.rb
|
48
|
+
- README.rdoc
|
49
|
+
- CHANGELOG.rdoc
|
50
|
+
- LICENSE.txt
|
51
|
+
homepage: https://github.com/daws/simply_configurable
|
52
|
+
licenses: []
|
53
|
+
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options:
|
56
|
+
- --main
|
57
|
+
- README.rdoc
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
hash: 3
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
version: "0"
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 3
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
requirements: []
|
79
|
+
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 1.8.10
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: Makes it simple to set arbitrary config key/value pairs on a class.
|
85
|
+
test_files: []
|
86
|
+
|