Class: Rascut::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/rascut/config.rb

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



16
17
18
19
# File 'lib/rascut/config.rb', line 16

def initialize
  @params = DEFAULT_CONFIG.dup
  @params[:logger].level = ::Logger::INFO
end

Instance Attribute Details

#paramsObject

Returns the value of attribute params.



20
21
22
# File 'lib/rascut/config.rb', line 20

def params
  @params
end

Instance Method Details

#[](name) ⇒ Object



22
23
24
# File 'lib/rascut/config.rb', line 22

def [](name)
  @params[name]
end

#loggerObject



26
27
28
# File 'lib/rascut/config.rb', line 26

def logger
  @params[:logger]
end

#merge_config(file) ⇒ Object



78
79
80
# File 'lib/rascut/config.rb', line 78

def merge_config(file)
  @params.merge!  YAML.load_file(file)
end

#parse_argv!(argv) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/rascut/config.rb', line 30

def parse_argv!(argv)
  op = OptionParser.new
  op.banner = 'Usage: $ rascut HelloWrold.as'

  #op.on('-a', 'Apollo compile mode') do |v| 
  #  @params[:apollo] = true
  #  @params[:compile_config] = '+configname=apollo' 
  #end

  op.on('-b=VAL', '--bind-address=VAL', 'server bind address(default 0.0.0.0)') {|v| @params[:bind_address] = v }
  op.on('--compile-config=VAL', '-c=VAL', 'mxmlc compile config ex:) --compile-config="-benchmark -strict=true"') do |v| 
    if @params[:compile_config]
      @params[:compile_config] << ' '  <<  v 
    else
      @params[:compile_config] = v 
    end
  end 

  op.on('--fcsh-cmd=VAL', 'fcsh command path') {|v| @params[:fcsh_cmd] = v }
  @params[:observe_files] = []
  op.on('-I=VAL', '--observe-files=VAL', 'observe files and directories path') {|v| @params[:observe_files] << v }

  if @params[:observe_files].empty?
    @params[:observe_files] << '.'
  end

  op.on('-i=VAL', '--interval=VAL', 'interval time(min)') {|v| @params[:interval] = v.to_i }
  op.on('-l=VAL', '--log=VAL', 'showing flashlog.txt') {|v| @params[:flashlog] = v }
  op.on('-m=VAL', '--mapping=VAL', 'server mapping path :example) -m "../assets=assets" -m "../images/=img"') {|v| 
    @params[:mapping] ||= []
    @params[:mapping] << v.split('=', 2)
  }
  op.on('--no-file-observe', "don't observing files") {|v| @params[:file_observing] = false }
  op.on('--observe-ext=VAL', 'observe ext ex:) --observe-ext="as3,actionscript3,css,mxml"') {|v| @params[:ext] = v.split(',') }
  op.on('--server', '-s', 'start autoreload webserver') {|v| @params[:server] = true }
  op.on('--server-handler=val', 'set server hander :example) --server-handler=webrick') {|v| @params[:server] = v }
  op.on('--port=val', '-p=val', 'server port(default: 3001)') {|v| @params[:port] = v.to_i }
  op.on('--plugin=VAL', 'load plugin(s)') {|v| 
    @params[:plugin] ||= []
    @params[:plugin] << v
  }
  op.on('-t=VAL', '--template=VAL', 'server use template file') {|v| @params[:template] = v }
  op.on('-v', '--verbose', 'detail messages') {|v| @params[:logger].level = Logger::DEBUG }
  op.on('--help', 'show this message') { puts op; Kernel::exit 1 }
  op.parse! argv
  @params[:logger].debug 'config' + @params.inspect
end