Class: Turbine::Application

Inherits:
Object
  • Object
show all
Includes:
CommandRunner, StandardCommands
Defined in:
lib/turbine/application.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from StandardCommands

#init

Methods included from CommandRunner

#init_and_exit, #parse_options, #run, #setup, #teardown

Constructor Details

#initializeApplication



55
56
57
58
59
60
# File 'lib/turbine/application.rb', line 55

def initialize
  @params        = {}
  @prompt        = HighLine.new
  @option_parser = OptionParser.new
  @turbine_dir   = nil
end

Class Attribute Details

.api_keyObject

Returns the value of attribute api_key.



52
53
54
# File 'lib/turbine/application.rb', line 52

def api_key
  @api_key
end

Instance Attribute Details

#commandObject

Returns the value of attribute command.



89
90
91
# File 'lib/turbine/application.rb', line 89

def command
  @command
end

#option_parserObject

Returns the value of attribute option_parser.



89
90
91
# File 'lib/turbine/application.rb', line 89

def option_parser
  @option_parser
end

#paramsObject

Returns the value of attribute params.



89
90
91
# File 'lib/turbine/application.rb', line 89

def params
  @params
end

#promptObject

Returns the value of attribute prompt.



89
90
91
# File 'lib/turbine/application.rb', line 89

def prompt
  @prompt
end

Class Method Details

.config_dir(dir = Pathname.new(".")) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/turbine/application.rb', line 11

def config_dir(dir = Pathname.new("."))
  turbine_dir = dir + ".turbine"
  if dir.children.include?(turbine_dir)
    turbine_dir.expand_path
  else
    return nil if dir.expand_path.root?
    config_dir(dir.parent)
  end
end

.current_projectObject



36
37
38
# File 'lib/turbine/application.rb', line 36

def current_project
  File.read("#{config_dir}/current_project").chomp
end

.current_project=(project) ⇒ Object



40
41
42
# File 'lib/turbine/application.rb', line 40

def current_project=(project)
  File.open("#{config_dir}/current_project", "w") { |f| f << project }
end

.current_project_urlObject



44
45
46
# File 'lib/turbine/application.rb', line 44

def current_project_url
  projects[current_project]
end

.extension(&block) ⇒ Object



32
33
34
# File 'lib/turbine/application.rb', line 32

def extension(&block)
  extensions << Module.new(&block)
end

.extensionsObject



28
29
30
# File 'lib/turbine/application.rb', line 28

def extensions
  @extensions ||= []
end

.global_config_dirObject



21
22
23
24
25
26
# File 'lib/turbine/application.rb', line 21

def global_config_dir
  path = File.expand_path("~/.turbine")
  if File.exist?(path)
    path
  end
end

.projectsObject



48
49
50
# File 'lib/turbine/application.rb', line 48

def projects
  JSON.parse(File.read("#{config_dir}/projects.json"))
end

Instance Method Details

#clear_log_dataObject



83
84
85
86
87
# File 'lib/turbine/application.rb', line 83

def clear_log_data
  write_file("log/#{self.class.api_key}.json") do |f|
    f << [].to_json
  end
end

#delete_file(name) ⇒ Object



71
72
73
# File 'lib/turbine/application.rb', line 71

def delete_file(name)
  rm_f "#{self.class.config_dir}/#{name}"
end

#load_log_dataObject



79
80
81
# File 'lib/turbine/application.rb', line 79

def load_log_data
  JSON.parse(File.read("#{self.class.config_dir}/log/#{self.class.api_key}.json"))
end

#read_file(name) ⇒ Object



62
63
64
65
# File 'lib/turbine/application.rb', line 62

def read_file(name)
  file = "#{self.class.config_dir}/#{name}"
  File.read(file) if File.exists?(file)
end

#serviceObject



75
76
77
# File 'lib/turbine/application.rb', line 75

def service
  RestClient::Resource.new(self.class.current_project_url, self.class.api_key, "")
end

#write_file(name, mode = "w") ⇒ Object



67
68
69
# File 'lib/turbine/application.rb', line 67

def write_file(name, mode="w")
  File.open("#{self.class.config_dir}/#{name}", mode) { |f| yield(f) }
end