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

Returns a new instance of Application.



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

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.



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

def api_key
  @api_key
end

Instance Attribute Details

#commandObject

Returns the value of attribute command.



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

def command
  @command
end

#option_parserObject

Returns the value of attribute option_parser.



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

def option_parser
  @option_parser
end

#paramsObject

Returns the value of attribute params.



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

def params
  @params
end

#promptObject

Returns the value of attribute prompt.



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

def prompt
  @prompt
end

Class Method Details

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



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

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



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

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

.current_project=(project) ⇒ Object



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

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

.current_project_urlObject



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

def current_project_url
  projects[current_project]
end

.extension(&block) ⇒ Object



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

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

.extensionsObject



20
21
22
# File 'lib/turbine/application.rb', line 20

def extensions
  @extensions ||= []
end

.projectsObject



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

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

Instance Method Details

#clear_log_dataObject



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

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

#delete_file(name) ⇒ Object



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

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

#load_log_dataObject



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

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

#read_file(name) ⇒ Object



54
55
56
# File 'lib/turbine/application.rb', line 54

def read_file(name)
  File.read("#{self.class.config_dir}/#{name}")
end

#serviceObject



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

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

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



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

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