Parent

BackgrounDRb::Config

Public Class Methods

parse_cmd_options(argv) click to toggle source

(Not documented)

    # File lib/backgroundrb/bdrb_config.rb, line 3
 3:     def self.parse_cmd_options(argv)
 4:       options = { }
 5: 
 6:       OptionParser.new do |opts|
 7:         script_name = File.basename($0)
 8:         opts.banner = "Usage: #{$0} [options]"
 9:         opts.separator ""
10:         opts.on("-e", "--environment=name", String,
11:                 "Specifies the environment to operate under (test/development/production).",
12:                 "Default: development") { |v| options[:environment] = v }
13:         opts.separator ""
14:         opts.on("-h", "--help",
15:                 "Show this help message.") { $stderr.puts opts; exit }
16:         opts.separator ""
17:         opts.on("-v","--version",
18:                 "Show version.") { $stderr.puts "1.1"; exit }
19:       end.parse!(argv)
20: 
21:       ENV["RAILS_ENV"] = options[:environment] if options[:environment]
22:     end
read_config(config_file) click to toggle source

(Not documented)

    # File lib/backgroundrb/bdrb_config.rb, line 24
24:     def self.read_config(config_file)
25:       config = YAML.load(ERB.new(IO.read(config_file)).result)
26:       environment = ENV["RAILS_ENV"] || config[:backgroundrb][:environment] || "development"
27: 
28:       if respond_to?(:silence_warnings)
29:         silence_warnings do
30:           Object.const_set("RAILS_ENV",environment)
31:         end
32:       else
33:         Object.const_set("RAILS_ENV",environment)
34:       end
35: 
36:       ENV["RAILS_ENV"] = environment
37:       config
38:     end

secsequence

--- SEC00010

seccomment

--- ""

method_list

--- 
- methods: 
  - visibility: public
    aref: M000028
    name: parse_cmd_options
    sourcecode: "    <span class=\"ruby-comment cmt\"># File lib/backgroundrb/bdrb_config.rb, line 3</span>\n 3:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">parse_cmd_options</span>(<span class=\"ruby-identifier\">argv</span>)\n 4:       <span class=\"ruby-identifier\">options</span> = { }\n 5: \n 6:       <span class=\"ruby-constant\">OptionParser</span>.<span class=\"ruby-identifier\">new</span> <span class=\"ruby-keyword kw\">do</span> <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">opts</span><span class=\"ruby-operator\">|</span>\n 7:         <span class=\"ruby-identifier\">script_name</span> = <span class=\"ruby-constant\">File</span>.<span class=\"ruby-identifier\">basename</span>(<span class=\"ruby-identifier\">$0</span>)\n 8:         <span class=\"ruby-identifier\">opts</span>.<span class=\"ruby-identifier\">banner</span> = <span class=\"ruby-node\">&quot;Usage: #{$0} [options]&quot;</span>\n 9:         <span class=\"ruby-identifier\">opts</span>.<span class=\"ruby-identifier\">separator</span> <span class=\"ruby-value str\">&quot;&quot;</span>\n\
      10:         <span class=\"ruby-identifier\">opts</span>.<span class=\"ruby-identifier\">on</span>(<span class=\"ruby-value str\">&quot;-e&quot;</span>, <span class=\"ruby-value str\">&quot;--environment=name&quot;</span>, <span class=\"ruby-constant\">String</span>,\n\
      11:                 <span class=\"ruby-value str\">&quot;Specifies the environment to operate under (test/development/production).&quot;</span>,\n\
      12:                 <span class=\"ruby-value str\">&quot;Default: development&quot;</span>) { <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">v</span><span class=\"ruby-operator\">|</span> <span class=\"ruby-identifier\">options</span>[<span class=\"ruby-identifier\">:environment</span>] = <span class=\"ruby-identifier\">v</span> }\n\
      13:         <span class=\"ruby-identifier\">opts</span>.<span class=\"ruby-identifier\">separator</span> <span class=\"ruby-value str\">&quot;&quot;</span>\n\
      14:         <span class=\"ruby-identifier\">opts</span>.<span class=\"ruby-identifier\">on</span>(<span class=\"ruby-value str\">&quot;-h&quot;</span>, <span class=\"ruby-value str\">&quot;--help&quot;</span>,\n\
      15:                 <span class=\"ruby-value str\">&quot;Show this help message.&quot;</span>) { <span class=\"ruby-identifier\">$stderr</span>.<span class=\"ruby-identifier\">puts</span> <span class=\"ruby-identifier\">opts</span>; <span class=\"ruby-identifier\">exit</span> }\n\
      16:         <span class=\"ruby-identifier\">opts</span>.<span class=\"ruby-identifier\">separator</span> <span class=\"ruby-value str\">&quot;&quot;</span>\n\
      17:         <span class=\"ruby-identifier\">opts</span>.<span class=\"ruby-identifier\">on</span>(<span class=\"ruby-value str\">&quot;-v&quot;</span>,<span class=\"ruby-value str\">&quot;--version&quot;</span>,\n\
      18:                 <span class=\"ruby-value str\">&quot;Show version.&quot;</span>) { <span class=\"ruby-identifier\">$stderr</span>.<span class=\"ruby-identifier\">puts</span> <span class=\"ruby-value str\">&quot;1.1&quot;</span>; <span class=\"ruby-identifier\">exit</span> }\n\
      19:       <span class=\"ruby-keyword kw\">end</span>.<span class=\"ruby-identifier\">parse!</span>(<span class=\"ruby-identifier\">argv</span>)\n\
      20: \n\
      21:       <span class=\"ruby-constant\">ENV</span>[<span class=\"ruby-value str\">&quot;RAILS_ENV&quot;</span>] = <span class=\"ruby-identifier\">options</span>[<span class=\"ruby-identifier\">:environment</span>] <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">options</span>[<span class=\"ruby-identifier\">:environment</span>]\n\
      22:     <span class=\"ruby-keyword kw\">end</span>"
    params: (argv)
  - visibility: public
    aref: M000029
    name: read_config
    sourcecode: "    <span class=\"ruby-comment cmt\"># File lib/backgroundrb/bdrb_config.rb, line 24</span>\n\
      24:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">read_config</span>(<span class=\"ruby-identifier\">config_file</span>)\n\
      25:       <span class=\"ruby-identifier\">config</span> = <span class=\"ruby-constant\">YAML</span>.<span class=\"ruby-identifier\">load</span>(<span class=\"ruby-constant\">ERB</span>.<span class=\"ruby-identifier\">new</span>(<span class=\"ruby-constant\">IO</span>.<span class=\"ruby-identifier\">read</span>(<span class=\"ruby-identifier\">config_file</span>)).<span class=\"ruby-identifier\">result</span>)\n\
      26:       <span class=\"ruby-identifier\">environment</span> = <span class=\"ruby-constant\">ENV</span>[<span class=\"ruby-value str\">&quot;RAILS_ENV&quot;</span>] <span class=\"ruby-operator\">||</span> <span class=\"ruby-identifier\">config</span>[<span class=\"ruby-identifier\">:backgroundrb</span>][<span class=\"ruby-identifier\">:environment</span>] <span class=\"ruby-operator\">||</span> <span class=\"ruby-value str\">&quot;development&quot;</span>\n\
      27: \n\
      28:       <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">respond_to?</span>(<span class=\"ruby-identifier\">:silence_warnings</span>)\n\
      29:         <span class=\"ruby-identifier\">silence_warnings</span> <span class=\"ruby-keyword kw\">do</span>\n\
      30:           <span class=\"ruby-constant\">Object</span>.<span class=\"ruby-identifier\">const_set</span>(<span class=\"ruby-value str\">&quot;RAILS_ENV&quot;</span>,<span class=\"ruby-identifier\">environment</span>)\n\
      31:         <span class=\"ruby-keyword kw\">end</span>\n\
      32:       <span class=\"ruby-keyword kw\">else</span>\n\
      33:         <span class=\"ruby-constant\">Object</span>.<span class=\"ruby-identifier\">const_set</span>(<span class=\"ruby-value str\">&quot;RAILS_ENV&quot;</span>,<span class=\"ruby-identifier\">environment</span>)\n\
      34:       <span class=\"ruby-keyword kw\">end</span>\n\
      35: \n\
      36:       <span class=\"ruby-constant\">ENV</span>[<span class=\"ruby-value str\">&quot;RAILS_ENV&quot;</span>] = <span class=\"ruby-identifier\">environment</span>\n\
      37:       <span class=\"ruby-identifier\">config</span>\n\
      38:     <span class=\"ruby-keyword kw\">end</span>"
    params: (config_file)
  category: Class
  type: Public

sectitle

--- 

[Validate]

Generated with the Darkfish Rdoc Generator.