Module: Tux::Commands

Defined in:
lib/tux/commands.rb

Constant Summary collapse

SETTINGS =
%w{methodoverride inline_templates}

Instance Method Summary collapse

Instance Method Details

#appObject



21
22
23
24
25
26
27
28
# File 'lib/tux/commands.rb', line 21

def app
  @app ||= begin
    obj = Tux.app_class.new!
    obj.request = Sinatra::Request.new({})
    obj.response = Sinatra::Response.new
    obj
  end
end

#routesObject



5
6
7
8
9
10
11
12
13
# File 'lib/tux/commands.rb', line 5

def routes
  Tux.app_class.routes.inject([]) {|arr, (k,v)|
    arr += v.map {|regex,params,*|
      path = params.empty? ? regex.inspect :
        params.inject(regex.inspect) {|s,e| s.sub(/\([^()]+\)/, ":#{e}") }
      [k, (str = path[%r{/\^(.*)\$/}, 1]) ? str.tr('\\', '') : path]
    }
  }
end

#settingsObject



15
16
17
18
19
# File 'lib/tux/commands.rb', line 15

def settings
  meths = (Tux.app_class.methods(false) + Sinatra::Base.methods(false)).
    sort.map(&:to_s).select {|e| e[/=$/] }.map {|e| e[0..-2] } - SETTINGS
  meths.map {|meth| [meth, (Tux.app_class.send(meth) rescue $!.inspect)] }
end