Class Rascut::Config
In: lib/rascut/config.rb
Parent: Object

Methods

[]   logger   merge_config   new   parse_argv!  

Constants

DEFAULT_CONFIG = { :interval => 1, :compile_config => nil, :file_observing => true, :fcsh_cmd => 'fcsh', :ext => ['as', 'css', 'mxml'], :logger => Rascut::Logger.new(STDOUT), }

Attributes

params  [RW] 

Public Class methods

[Source]

    # File lib/rascut/config.rb, line 16
16:     def initialize
17:       @params = DEFAULT_CONFIG.dup
18:       @params[:logger].level = ::Logger::INFO
19:     end

Public Instance methods

[Source]

    # File lib/rascut/config.rb, line 22
22:     def [](name)
23:       @params[name]
24:     end

[Source]

    # File lib/rascut/config.rb, line 26
26:     def logger
27:       @params[:logger]
28:     end

[Source]

    # File lib/rascut/config.rb, line 82
82:     def merge_config(file)
83:       @params.merge!  YAML.load_file(file)
84:     end

[Source]

    # File lib/rascut/config.rb, line 30
30:     def parse_argv!(argv)
31:       op = OptionParser.new
32:       op.banner = 'Usage: $ rascut HelloWrold.as'
33: 
34:       #op.on('-a', 'Apollo compile mode') do |v| 
35:       #  @params[:apollo] = true
36:       #  @params[:compile_config] = '+configname=apollo' 
37:       #end
38: 
39:       op.on('-b=VAL', '--bind-address=VAL', 'server bind address(default 0.0.0.0)') {|v| @params[:bind_address] = v }
40:       op.on('--compile-config=VAL', '-c=VAL', 'mxmlc compile config ex:) --compile-config="-benchmark -strict=true"') do |v| 
41:         if @params[:compile_config]
42:           @params[:compile_config] << ' '  <<  v 
43:         else
44:           @params[:compile_config] = v 
45:         end
46:       end 
47: 
48:       op.on('--fcsh-cmd=VAL', 'fcsh command path') {|v| @params[:fcsh_cmd] = v }
49:       @params[:observe_files] = []
50:       op.on('-I=VAL', '--observe-files=VAL', 'observe files and directories path') {|v| @params[:observe_files] << v }
51: 
52:       if @params[:observe_files].empty?
53:         @params[:observe_files] << '.'
54:       end
55: 
56:       op.on('-h', '--help', 'show this message') { puts op; Kernel::exit 1 }
57:       op.on('-i=VAL', '--interval=VAL', 'interval time(min)') {|v| @params[:interval] = v.to_i }
58:       op.on('-l=VAL', '--log=VAL', 'showing flashlog.txt') {|v| @params[:flashlog] = v }
59:       op.on('-m=VAL', '--mapping=VAL', 'server mapping path :example) -m "../assets=assets" -m "../images/=img"') {|v| 
60:         @params[:mapping] ||= []
61:         @params[:mapping] << v.split('=', 2)
62:       }
63:       op.on('--no-file-observe', "don't observing files") {|v| @params[:file_observing] = false }
64:       op.on('--observe-ext=VAL', 'observe ext ex:) --observe-ext="as3,actionscript3,css,mxml"') {|v| @params[:ext] = v.split(',') }
65:       op.on('--server', '-s', 'start autoreload webserver') {|v| @params[:server] = true }
66:       op.on('--server-handler=val', 'set server hander :example) --server-handler=webrick') {|v| @params[:server] = v }
67:       op.on('--port=val', '-p=val', 'server port(default: 3001)') {|v| @params[:port] = v.to_i }
68:       op.on('--plugin=VAL', 'load plugin(s)') {|v| 
69:         @params[:plugin] ||= []
70:         @params[:plugin] << v
71:       }
72:       op.on('-t=VAL', '--template=VAL', 'server use template file') {|v| @params[:template] = v }
73:       op.on('-v', '--verbose', 'detail messages') {|v| @params[:logger].level = Logger::DEBUG }
74:       op.on('--version', 'show version') {|v| 
75:         puts "rascut #{Rascut::VERSION}"
76:         exit 0
77:       }
78:       op.parse! argv
79:       @params[:logger].debug 'config' + @params.inspect
80:     end

[Validate]