Class: Zimt::Sprinkle

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

Constant Summary collapse

LICENSES =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spec) ⇒ Sprinkle

Returns a new instance of Sprinkle.



36
37
38
39
40
41
# File 'lib/zimt/sprinkle.rb', line 36

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

#specObject

Returns the value of attribute spec.



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

def spec
  @spec
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



26
27
28
29
30
31
32
33
34
# File 'lib/zimt/sprinkle.rb', line 26

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

Instance Method Details

#installObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/zimt/sprinkle.rb', line 43

def install
  puts "Installing #{name}"
  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)
    elsif file.end_with? ".h"
      Zimt.pbxproj.add_h_file(file)
    else
      Zimt.pbxproj.add_resource_file(file)
    end
  end

  if(spec["license"] || spec["copyright"])
    puts "Licensed under #{spec["license"]}"
    Zimt.pbxproj.ensure_license_file
    open(Pathname.new("Zimt").join("3rdPartyLicenses.txt"), "a") do |io|
      io.write "License for #{name}:\n\n"
      io.write spec["copyright"]
      io.write "\n\n"
      license = LICENSES[spec["license"]] || "#{spec["license"]}\n"
      io.write license
      io.write "\n----------\n\n"
    end
  end

  puts "All done"
end