Class: Comet::Kata

Inherits:
Object
  • Object
show all
Defined in:
lib/comet/kata.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Kata



6
7
8
9
10
11
12
# File 'lib/comet/kata.rb', line 6

def initialize(params)
  @id = params[:id]
  @name = params[:name]
  @slug = params[:slug]
  @download_link = params[:download_link]
  @basedir = params[:basedir]
end

Instance Attribute Details

#basedirObject (readonly)

Returns the value of attribute basedir.



4
5
6
# File 'lib/comet/kata.rb', line 4

def basedir
  @basedir
end

Returns the value of attribute download_link.



4
5
6
# File 'lib/comet/kata.rb', line 4

def download_link
  @download_link
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/comet/kata.rb', line 4

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/comet/kata.rb', line 4

def name
  @name
end

#slugObject (readonly)

Returns the value of attribute slug.



4
5
6
# File 'lib/comet/kata.rb', line 4

def slug
  @slug
end

Class Method Details

.find(config, id) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/comet/kata.rb', line 25

def self.find(config, id)
  kata_info = Comet::API.get_kata(config, id)

  if kata_info.nil?
    raise ArgumentError.new("Could not find kata with id = #{id}")
  else
    Comet::Kata.new(kata_info.merge({ basedir: config['basedir'] }))
  end
end

.find_kata_dir(dir) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/comet/kata.rb', line 35

def self.find_kata_dir(dir)
  kata_file = File.join(dir, '.kata')

  if File.exists?(kata_file)
    kata_file
  else
    parent_dir = File.dirname(dir)

    if parent_dir != '/' && parent_dir != '.'
      find_kata_dir(parent_dir)
    else
      nil
    end
  end
end

.list(config) ⇒ Object



21
22
23
# File 'lib/comet/kata.rb', line 21

def self.list(config)
  Comet::API.get_katas(config)
end

Instance Method Details

#downloadObject



14
15
16
17
18
19
# File 'lib/comet/kata.rb', line 14

def download
  archive = Comet::API.download_archive(download_link, File.join(basedir, "#{slug}.tar.gz"))
  `tar zxf #{Shellwords.escape(archive)} -C #{Shellwords.escape(basedir)}`
  File.delete(archive)
  File.join(basedir, slug)
end