Class: Extension

Inherits:
Object show all
Defined in:
lib/commands/extension.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, name = nil) ⇒ Extension

Returns a new instance of Extension.



42
43
44
45
# File 'lib/commands/extension.rb', line 42

def initialize(uri, name=nil)
  @uri = uri
  guess_name(uri)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



40
41
42
# File 'lib/commands/extension.rb', line 40

def name
  @name
end

#uriObject (readonly)

Returns the value of attribute uri.



40
41
42
# File 'lib/commands/extension.rb', line 40

def uri
  @uri
end

Instance Method Details

#git_url?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/commands/extension.rb', line 55

def git_url?
  @uri =~ /^git:\/\// || @uri =~ /\.git$/
end

#install(options = {}) ⇒ Object



63
64
65
66
67
68
69
70
71
72
# File 'lib/commands/extension.rb', line 63

def install(options = {})
  method = :clone
  uninstall if installed? and options[:force]

  unless installed?
    send("install_using_#{method}", options)
  else
    puts "already installed: #{name} (#{uri}).  pass --force to reinstall"
  end
end

#installed?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/commands/extension.rb', line 59

def installed?
  File.directory?("#{spree_env.root}/vendor/extensions/#{name}")
end

#svn_url?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/commands/extension.rb', line 51

def svn_url?
  @uri =~ /svn(?:\+ssh)?:\/\/*/
end

#to_sObject



47
48
49
# File 'lib/commands/extension.rb', line 47

def to_s
  "#{@name.ljust(30)}#{@uri}"
end

#uninstallObject



74
75
76
77
78
79
80
81
82
# File 'lib/commands/extension.rb', line 74

def uninstall
  path = "#{spree_env.root}/vendor/extensions/#{name}"
  if File.directory?(path)
    puts "Removing 'vendor/extensions/#{name}'" if $verbose
    rm_r path
  else
    puts "Extension doesn't exist: #{path}"
  end
end