Class: Zimt::Sprinkle

Inherits:
Object
  • Object
show all
Defined in:
lib/zimt/sprinkle.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spec) ⇒ Sprinkle

Returns a new instance of Sprinkle.



15
16
17
18
19
20
# File 'lib/zimt/sprinkle.rb', line 15

def initialize(spec)
  @spec = spec
  @name = spec["name"]
  @url = spec["url"]
  @files = spec["files"]
end

Instance Attribute Details

#filesObject

Returns the value of attribute files.



3
4
5
# File 'lib/zimt/sprinkle.rb', line 3

def files
  @files
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/zimt/sprinkle.rb', line 3

def name
  @name
end

#urlObject

Returns the value of attribute url.



3
4
5
# File 'lib/zimt/sprinkle.rb', line 3

def url
  @url
end

Class Method Details

.get(name) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/zimt/sprinkle.rb', line 5

def self.get(name)
  if name.start_with?('http://') || name.start_with?('https://')
    url = name
  else
    url = "https://raw.github.com/zimt/sprinkles/stable/#{name.downcase}.sprinkle.yml"
  end
  spec = open(url) { |f| YAML::load(f) }
  self.new(spec)
end

Instance Method Details

#installObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/zimt/sprinkle.rb', line 22

def install
  puts "Installing #{name}"
  FileUtils.mkdir "Zimt" if not File.exists? "Zimt"
  Zimt.pbxproj.ensure_zimt_group
  files.each do |url|
    file = Pathname.new(URI.parse(url).path).basename('.sprinkle.yml').to_s
    puts "Adding #{file}..."
    open(Pathname.new("Zimt").join(file), "w") do |io|
      io.write(open(url).read)
    end
    if file.end_with? ".m"
      Zimt.pbxproj.add_m_file(file)
    else
      Zimt.pbxproj.add_h_file(file)
    end
  end
  puts "All done"
end