Class: Ramaze::Option::Holder
Instance Method Summary
collapse
Methods included from Merger
#merge!, #merge_cli!, #merge_prefixed!, #option_parser
Constructor Details
#initialize(options = {}) ⇒ Holder
Returns a new instance of Holder.
11
12
13
14
15
16
17
|
# File 'lib/ramaze/option/holder.rb', line 11
def initialize(options = {})
@members = Set.new
options.each do |key, value|
add_option(key, value, complain = false)
end
end
|
Instance Method Details
30
31
32
|
# File 'lib/ramaze/option/holder.rb', line 30
def [](key)
__send__(key)
end
|
#[]=(key, value) ⇒ Object
34
35
36
37
|
# File 'lib/ramaze/option/holder.rb', line 34
def []=(key, value)
@members << key.to_s.to_sym
__send__("#{key}=", value)
end
|
98
99
100
|
# File 'lib/ramaze/option/holder.rb', line 98
def adapter
find_from_aliases(@adapter, :adapter_aliases, Ramaze::Adapter, "ramaze/adapter")
end
|
#add_option(key, value, complain = true) ⇒ Object
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/ramaze/option/holder.rb', line 19
def add_option(key, value, complain = true)
Log.warn("Adding #{key} to #{self}") if complain
self.class.class_eval do
attr_reader key unless method_defined?(key)
attr_writer key unless method_defined?("#{key}=")
end
self[key] = value
end
|
102
103
104
|
# File 'lib/ramaze/option/holder.rb', line 102
def cache
find_from_aliases(@cache, :cache_aliases, Ramaze, "ramaze/cache")
end
|
41
42
43
44
45
|
# File 'lib/ramaze/option/holder.rb', line 41
def each
@members.each do |member|
yield member, self[member]
end
end
|
#port=(number) ⇒ Object
69
70
71
|
# File 'lib/ramaze/option/holder.rb', line 69
def port=(number)
@port = number.to_i
end
|
#public_root ⇒ Object
Find a suitable public_root, if none of these is a directory just use the currently set one.
79
80
81
82
83
|
# File 'lib/ramaze/option/holder.rb', line 79
def public_root
[ @public_root,
File.join(root, @public_root)
].find{|path| File.directory?(path) } || @public_root
end
|
#public_root=(pr) ⇒ Object
73
74
75
|
# File 'lib/ramaze/option/holder.rb', line 73
def public_root=(pr)
@public_root = pr
end
|
#setup(hash = {}) {|_self| ... } ⇒ Object
batch-assignment of key/value from hash, yields self if a block is given.
62
63
64
65
|
# File 'lib/ramaze/option/holder.rb', line 62
def setup(hash = {})
merge!(hash)
yield(self) if block_given?
end
|
#sourcereload=(interval) ⇒ Object
106
107
108
|
# File 'lib/ramaze/option/holder.rb', line 106
def sourcereload=(interval)
Ramaze::Reloader::OPTIONS[:cooldown] = interval
end
|
#startup(options) ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/ramaze/option/holder.rb', line 47
def startup(options)
options.each do |key, value|
self[key] = value
end
merge!(ARGV)
merge!(ENV)
self.root ||= File.dirname(File.expand_path(runner))
[self.load_engines].flatten.compact.each do |engine|
Ramaze::Template.const_get(engine)
end
end
|
#view_root ⇒ Object
Find a suitable view_root, if none of these is a directory just use the currently set one.
91
92
93
94
95
96
|
# File 'lib/ramaze/option/holder.rb', line 91
def view_root
[ @view_root,
File.join(root, @view_root),
File.join(root, 'template'),
].find{|path| File.directory?(path) } || @view_root
end
|
#view_root=(vr) ⇒ Object
85
86
87
|
# File 'lib/ramaze/option/holder.rb', line 85
def view_root=(vr)
@view_root = vr
end
|