choices 0.1.0 → 0.2.0
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.
- data/lib/choices.rb +2 -9
- data/lib/choices/rails.rb +52 -0
- metadata +5 -4
data/lib/choices.rb
CHANGED
@@ -28,13 +28,6 @@ module Choices
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
if defined? Rails
|
32
|
-
|
33
|
-
def from_file(name)
|
34
|
-
file = self.root + 'config' + name
|
35
|
-
Choices.load_settings(file, Rails.env.to_s).each do |key, value|
|
36
|
-
self.send("#{key}=", value)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
31
|
+
if defined? Rails
|
32
|
+
require 'choices/rails'
|
40
33
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'choices'
|
2
|
+
|
3
|
+
module Choices::Rails
|
4
|
+
def self.included(base)
|
5
|
+
base.class_eval do
|
6
|
+
def initialize_with_choices(*args, &block)
|
7
|
+
initialize_without_choices(*args, &block)
|
8
|
+
@choices = Hashie::Mash.new
|
9
|
+
end
|
10
|
+
|
11
|
+
alias :initialize_without_choices :initialize
|
12
|
+
alias :initialize :initialize_with_choices
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def from_file(name)
|
17
|
+
root = self.respond_to?(:root) ? self.root : Rails.root
|
18
|
+
file = root + 'config' + name
|
19
|
+
|
20
|
+
settings = Choices.load_settings(file, RAILS_ENV)
|
21
|
+
@choices.update settings
|
22
|
+
|
23
|
+
settings.each do |key, value|
|
24
|
+
self.send("#{key}=", value)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
if defined? Rails::Application::Configuration
|
30
|
+
Rails::Application::Configuration.send(:include, Choices::Rails)
|
31
|
+
elsif defined? Rails::Configuration
|
32
|
+
Rails::Configuration.class_eval do
|
33
|
+
include Choices::Rails
|
34
|
+
include Module.new {
|
35
|
+
def respond_to?(method)
|
36
|
+
super or method.to_s =~ /=$/ or (method.to_s =~ /\?$/ and @choices.key?($`))
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def method_missing(method, *args, &block)
|
42
|
+
if method.to_s =~ /=$/ or (method.to_s =~ /\?$/ and @choices.key?($`))
|
43
|
+
@choices.send(method, *args)
|
44
|
+
elsif @choices.key?(method)
|
45
|
+
@choices[method]
|
46
|
+
else
|
47
|
+
super
|
48
|
+
end
|
49
|
+
end
|
50
|
+
}
|
51
|
+
end
|
52
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: choices
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "Mislav Marohni\xC4\x87"
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-10-
|
18
|
+
date: 2010-10-25 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -44,6 +44,7 @@ extra_rdoc_files: []
|
|
44
44
|
|
45
45
|
files:
|
46
46
|
- Rakefile
|
47
|
+
- lib/choices/rails.rb
|
47
48
|
- lib/choices.rb
|
48
49
|
- README.md
|
49
50
|
has_rdoc: false
|