Class: Rsense::Server::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/rsense/server/options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Options

Returns a new instance of Options.



10
11
12
13
14
# File 'lib/rsense/server/options.rb', line 10

def initialize(opts)
  @rest = {}
  @command = opts["command"] if opts["command"]
  parse_args(opts)
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



8
9
10
# File 'lib/rsense/server/options.rb', line 8

def code
  @code
end

#commandObject

Returns the value of attribute command.



8
9
10
# File 'lib/rsense/server/options.rb', line 8

def command
  @command
end

#configObject

Returns the value of attribute config.



8
9
10
# File 'lib/rsense/server/options.rb', line 8

def config
  @config
end

#debugObject

Returns the value of attribute debug.



8
9
10
# File 'lib/rsense/server/options.rb', line 8

def debug
  @debug
end

#fileObject

Returns the value of attribute file.



8
9
10
# File 'lib/rsense/server/options.rb', line 8

def file
  @file
end

#locationObject

Returns the value of attribute location.



8
9
10
# File 'lib/rsense/server/options.rb', line 8

def location
  @location
end

#logObject

Returns the value of attribute log.



8
9
10
# File 'lib/rsense/server/options.rb', line 8

def log
  @log
end

#log_levelObject

Returns the value of attribute log_level.



8
9
10
# File 'lib/rsense/server/options.rb', line 8

def log_level
  @log_level
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/rsense/server/options.rb', line 8

def name
  @name
end

#prefixObject

Returns the value of attribute prefix.



8
9
10
# File 'lib/rsense/server/options.rb', line 8

def prefix
  @prefix
end

#project_pathObject

Returns the value of attribute project_path.



8
9
10
# File 'lib/rsense/server/options.rb', line 8

def project_path
  @project_path
end

#restObject

Returns the value of attribute rest.



8
9
10
# File 'lib/rsense/server/options.rb', line 8

def rest
  @rest
end

Instance Method Details

#debug?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/rsense/server/options.rb', line 42

def debug?
  @debug
end

#here_doc_reader(reader) ⇒ Object



38
39
40
# File 'lib/rsense/server/options.rb', line 38

def here_doc_reader(reader)
  Rsense::Util::HereDocReader.new(reader, "EOF")
end

#inherit(parent) ⇒ Object



66
67
68
69
70
71
72
73
74
# File 'lib/rsense/server/options.rb', line 66

def inherit(parent)
  if parent.debug?
    @debug = true
  end
  @log = parent.log()
  @log_level = parent.log_level
  @load_path = parent.load_path
  @gem_path = parent.gem_path
end

#load_config(config) ⇒ Object



76
77
78
79
80
81
82
83
84
# File 'lib/rsense/server/options.rb', line 76

def load_config(config)
  path = Pathname.new(config).expand_path
  if path.exist?
    json = JSON.parse(path.read)
    parse_args(json)
  else
    puts "Config file: #{path} does not exist"
  end
end

#parse_args(opts) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/rsense/server/options.rb', line 16

def parse_args(opts)
  opts.each_pair do |k, v|
    if respond_to?("#{k}=")
      __send__("#{k}=", v)
    else
      @rest[k] = v
    end
  end
end

#progressObject



58
59
60
61
62
63
64
# File 'lib/rsense/server/options.rb', line 58

def progress
  if @progress
    @progress.to_i
  else
    0
  end
end

#projectObject



26
27
28
# File 'lib/rsense/server/options.rb', line 26

def project
  @project_path
end

#project=(path) ⇒ Object



30
31
32
# File 'lib/rsense/server/options.rb', line 30

def project=(path)
  @project_path = Pathname.new(path).expand_path
end