Module: Sinatra::Namespace
- Defined in:
- lib/sinatra/namespace.rb
Defined Under Namespace
Modules: InstanceMethods, NestedMethods
Constant Summary
collapse
- DONT_FORWARD =
%w[call configure disable enable new register reset! run! set use template]
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.make_namespace(mod, options = {}) ⇒ Object
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/sinatra/namespace.rb', line 134
def self.make_namespace(mod, options = {})
unless options[:base] ||= options[:for]
base = mod
base = base.parent until base.is_a? Class
raise ArgumentError, "base class not given/detected" if base == Object
options[:base] = base
end
options[:prefix] ||= "/" << mod.name.gsub(/^#{options[:base]}::/, '').to_const_path
mod.extend self
mod.extend NestedMethods
options.each { |k,v| mod.send(k, v) }
mod.send(:always_activate) if options[:base].always_activate_namespaces?
mod
end
|
.registered(klass) ⇒ Object
128
129
130
131
132
|
# File 'lib/sinatra/namespace.rb', line 128
def self.registered(klass)
klass.register Sinatra::Sugar
klass.__send__ :include, InstanceMethods
klass.enable :merge_namespaces, :auto_namespace, :always_activate_namespaces
end
|
Instance Method Details
#make_namespace(mod, options = {}) ⇒ Object
183
184
185
|
# File 'lib/sinatra/namespace.rb', line 183
def make_namespace(mod, options = {})
Sinatra::Namespace.make_namespace mod, options.merge(:base => self)
end
|
#make_namespace?(klass, meth) ⇒ Boolean
206
207
208
209
210
211
212
213
214
|
# File 'lib/sinatra/namespace.rb', line 206
def make_namespace?(klass, meth)
return false if !auto_namespace? or klass.is_a? NestedMethods
meths = NestedMethods.instance_methods.map { |m| m.to_s }
if auto_namespace != true
meths = [auto_namespace[:only]].flatten.map { |m| m.to_s } if auto_namespace.include? :only
[auto_namespace[:except]].flatten.each { |m| meths.delete m.to_s } if auto_namespace.include? :except
end
meths.include? meth.to_s
end
|
#namespace(prefix, merge = nil, &block) ⇒ Object
187
188
189
190
191
192
193
194
195
196
197
198
|
# File 'lib/sinatra/namespace.rb', line 187
def namespace(prefix, merge = nil, &block)
if merge or (merge.nil? and merge_namespaces?)
@namespaces ||= {}
@namespaces[prefix] ||= namespace prefix, false
@namespaces[prefix].class_eval(&block) if block
@namespaces[prefix]
else
mod = make_namespace Module.new, :prefix => prefix
mod.class_eval(&block) if block
mod
end
end
|
#nested_method_missing(klass, meth, *args, &block) ⇒ Object
200
201
202
203
204
|
# File 'lib/sinatra/namespace.rb', line 200
def nested_method_missing(klass, meth, *args, &block)
return super unless make_namespace? klass, meth
make_namespace klass
klass.send(meth, *args, &block)
end
|