Module: Pez::Base

Defined in:
lib/pez/base.rb

Class Method Summary collapse

Class Method Details

.add_to_config(name, url, options = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/pez/base.rb', line 27

def self.add_to_config(name, url, options={})
  c = config
  c ||= {}
  c[name] = {
    'repo' => url, 
    'type' => options[:type], 
    'revision' => options[:revision], 
    'branch' => options[:branch]
  }.reject {|key, value| value.nil? }
  
  File.open('config/plugins.yml', 'w+') do |f|
    f << YAML::dump(c)
  end
end

.configObject



23
24
25
# File 'lib/pez/base.rb', line 23

def self.config
  YAML.load_file('config/plugins.yml')
end

.destinationObject



55
56
57
58
59
60
61
62
# File 'lib/pez/base.rb', line 55

def self.destination
  if File.exists?(File.expand_path('~/.pezrc'))
    c = YAML.load_file(File.expand_path('~/.pezrc'))
  else
    c = YAML.load_file('config/pez.yml')
  end
  File.expand_path(c[Rails.env] || 'tmp/plugins')
end

.git?(url, options = {}) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/pez/base.rb', line 7

def self.git?(url, options={})
  options["type"] == "git" || url =~ /^git:/ || url =~ /\.git$/
end

.name(url, options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/pez/base.rb', line 11

def self.name(url, options={})
  return options[:name] if options[:name]
  
  if git?(url, options)
    m, name = *url.match(/\/([^\/]+)\.git$/)
  else
    m, name = *url.match(/\/([^\/]+)\/?(?:trunk\/?)?$/)
  end
  
  name
end

.plugins(name, options = {}) ⇒ Object



64
65
66
67
68
69
70
71
72
# File 'lib/pez/base.rb', line 64

def self.plugins(name, options={})
  if name
    [name]
  elsif options[:all]
    Pez::Base.config ? (Pez::Base.config).keys : []
  else
    []
  end
end

.remove_from_config(name) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/pez/base.rb', line 42

def self.remove_from_config(name)
  c = config
  c ||= {}
  c.delete(name)
  
  File.open('config/plugins.yml', 'w+') do |f|
    f << YAML::dump(c)
  end
  
  system %( rm -rf #{destination}/#{name} )
  system %( rm vendor/plugins/#{name} )
end