Class: Relish::Command::Base
- Inherits:
-
Object
- Object
- Relish::Command::Base
show all
- Defined in:
- lib/relish/commands/base.rb
Constant Summary
collapse
- DEFAULT_HOST =
'relishapp.com'
- GLOBAL_OPTIONS_FILE =
File.join(File.expand_path('~'), '.relish')
- LOCAL_OPTIONS_FILE =
'.relish'
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(args = []) ⇒ Base
Returns a new instance of Base.
12
13
14
15
16
|
# File 'lib/relish/commands/base.rb', line 12
def initialize(args = [])
@args = args
@param = get_param
@options = get_options
end
|
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
10
11
12
|
# File 'lib/relish/commands/base.rb', line 10
def args
@args
end
|
Instance Method Details
#api_token ⇒ Object
34
35
36
|
# File 'lib/relish/commands/base.rb', line 34
def api_token
parsed_options_file['api_token']
end
|
#get_options ⇒ Object
42
43
44
|
# File 'lib/relish/commands/base.rb', line 42
def get_options
parsed_options_file.merge(Hash[*args])
end
|
#get_param ⇒ Object
38
39
40
|
# File 'lib/relish/commands/base.rb', line 38
def get_param
args.shift if args.size.odd?
end
|
#organization ⇒ Object
18
19
20
|
# File 'lib/relish/commands/base.rb', line 18
def organization
@options['--organization'] || @options['-o'] || parsed_options_file['organization']
end
|
#parsed_options_file ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/relish/commands/base.rb', line 46
def parsed_options_file
@parsed_options_file ||= {}.tap do |parsed_options|
[GLOBAL_OPTIONS_FILE, LOCAL_OPTIONS_FILE].each do |options_file|
parsed_options.merge!(YAML.load_file(options_file)) if File.exist?(options_file)
end
end
end
|
#project ⇒ Object
22
23
24
|
# File 'lib/relish/commands/base.rb', line 22
def project
@options['--project'] || @options['-p'] || parsed_options_file['project']
end
|
#resource ⇒ Object
30
31
32
|
# File 'lib/relish/commands/base.rb', line 30
def resource
RestClient::Resource.new(url)
end
|
#url ⇒ Object
26
27
28
|
# File 'lib/relish/commands/base.rb', line 26
def url
"http://#{@options['--host'] || DEFAULT_HOST}/api"
end
|