Class: Sinatra::BigBand

Inherits:
Base
  • Object
show all
Defined in:
lib/sinatra/big_band.rb

Class Method Summary collapse

Class Method Details

.apply_options(klass) ⇒ Object



39
40
41
42
43
# File 'lib/sinatra/big_band.rb', line 39

def self.apply_options(klass)
  klass.set :app_file, klass.caller_files.first.expand_path unless klass.app_file?
  klass.set :haml, :format => :html5, :escape_html => true
  enable :sessions, :method_override, :show_exceptions
end

.generate_subclass(options = {}) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/sinatra/big_band.rb', line 58

def self.generate_subclass(options = {})
  options[:except] ||= []
  options.keys.each { |k| raise ArgumentError, "unkown option #{k.inspect}" unless k == :except }
  options[:except] = [*options[:except]]
  list = subclass_extensions.inject([]) do |chosen, (ident, (parent, name, dev, block))|
    next chosen if options[:except].include? ident or (dev and not development?)
    block ||= proc { |klass| klass.register parent.const_get(name) }
    chosen << block
  end
  subclass_for list, "#{self}(#{options.inspect[1..-2]})"
end

.subclass_extension(path, development_only = false, parent = Sinatra, &block) ⇒ Object



14
15
16
17
18
# File 'lib/sinatra/big_band.rb', line 14

def self.subclass_extension(path, development_only = false, parent = Sinatra, &block)
  name = path.to_s.split('_').map { |e| e.capitalize }.join.to_sym
  subclass_extensions[name] ||= [parent, name, development_only, block]
  parent.autoload name, "#{parent.name.downcase}/#{path}" if parent
end

.subclass_extensionsObject



10
11
12
# File 'lib/sinatra/big_band.rb', line 10

def self.subclass_extensions
  @subclass_extensions ||= {}
end

.subclass_for(list, inspection = nil) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/sinatra/big_band.rb', line 45

def self.subclass_for(list, inspection = nil)
  @subclasses ||= {}
  @subclasses[list] ||= Class.new(self) do
    @inspection = inspection
    define_singleton_method(:inspect) { @inspection || super() }
    define_singleton_method(:inherited) do |klass|
      super klass
      list.each { |block| block.call klass }
      apply_options klass
    end
  end
end