Class: Relish::Command::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/relish/commands/base.rb

Direct Known Subclasses

Config, Help, Projects, Push

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

#argsObject

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_tokenObject



34
35
36
# File 'lib/relish/commands/base.rb', line 34

def api_token
  parsed_options_file['api_token']
end

#get_optionsObject



42
43
44
# File 'lib/relish/commands/base.rb', line 42

def get_options
  parsed_options_file.merge(Hash[*args])
end

#get_paramObject



38
39
40
# File 'lib/relish/commands/base.rb', line 38

def get_param
  args.shift if args.size.odd?
end

#organizationObject



18
19
20
# File 'lib/relish/commands/base.rb', line 18

def organization
  @options['--organization'] || @options['-o'] || parsed_options_file['organization']
end

#parsed_options_fileObject



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

#projectObject



22
23
24
# File 'lib/relish/commands/base.rb', line 22

def project
  @options['--project'] || @options['-p'] || parsed_options_file['project']
end

#resourceObject



30
31
32
# File 'lib/relish/commands/base.rb', line 30

def resource
  RestClient::Resource.new(url)
end

#urlObject



26
27
28
# File 'lib/relish/commands/base.rb', line 26

def url
  "http://#{@options['--host'] || DEFAULT_HOST}/api"
end