Class: Greenhouse::Projects::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/greenhouse/projects/project.rb

Direct Known Subclasses

Application, Engine, Gem

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, args = {}) ⇒ Project

Returns a new instance of Project.



16
17
18
19
20
21
22
# File 'lib/greenhouse/projects/project.rb', line 16

def initialize(name, args={})
  @name = name
  @title = args.delete(:title) || name.camelize
  @ignored = (args.has_key?(:ignore) ? [args.delete(:ignore)] : []).flatten
  @repository = Repository.new(name, args)
  @ignore_file = Resources::IgnoreFile.new("#{path}/.ignore")
end

Class Attribute Details

.subclassesObject (readonly)

Returns the value of attribute subclasses.



7
8
9
# File 'lib/greenhouse/projects/project.rb', line 7

def subclasses
  @subclasses
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/greenhouse/projects/project.rb', line 4

def name
  @name
end

#repositoryObject

Returns the value of attribute repository.



4
5
6
# File 'lib/greenhouse/projects/project.rb', line 4

def repository
  @repository
end

#titleObject

Returns the value of attribute title.



4
5
6
# File 'lib/greenhouse/projects/project.rb', line 4

def title
  @title
end

Class Method Details

.inherited(subclass) ⇒ Object

Keep track of inheriting classes (to use as project “types”)



10
11
12
# File 'lib/greenhouse/projects/project.rb', line 10

def inherited(subclass)
  (@subclasses ||= [self]) << subclass
end

Instance Method Details

#bundle(cmd = 'install') ⇒ Object

Go into the local directory and run Bundler



60
61
62
63
64
65
66
67
68
# File 'lib/greenhouse/projects/project.rb', line 60

def bundle(cmd='install')
  raise "Directory does not exist: #{path}" unless exists?
  Dir.chdir(path) do
    Bundler.with_clean_env do
      # TODO look into using Bundler to install instead of executing system cmd
      Greenhouse::CLI::exec "bundle #{cmd.to_s} 2>&1"
    end
  end
end

#chdir(&block) ⇒ Object



28
29
30
# File 'lib/greenhouse/projects/project.rb', line 28

def chdir(&block)
  Dir.chdir(path, &block)
end

#destroyObject

Remove the project directory



71
72
73
# File 'lib/greenhouse/projects/project.rb', line 71

def destroy
  @repository.destroy # use the repository object to destroy itself/directory
end

#exists?Boolean

Check if the repository exists

Returns:

  • (Boolean)


47
48
49
# File 'lib/greenhouse/projects/project.rb', line 47

def exists?
  @repository.exists?
end

#gemfileObject



37
38
39
40
# File 'lib/greenhouse/projects/project.rb', line 37

def gemfile
  return nil unless gemfile?
  "#{path}/Gemfile"
end

#gemfile?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/greenhouse/projects/project.rb', line 42

def gemfile?
  chdir { return File.exists?("Gemfile") }
end

#ignoredObject



24
25
26
# File 'lib/greenhouse/projects/project.rb', line 24

def ignored
  Projects.ignored.concat(@ignore_file.ignored).concat(@ignored)
end

#pathObject

Return the local path to the project repo



33
34
35
# File 'lib/greenhouse/projects/project.rb', line 33

def path
  @repository.path
end

#to_argObject



55
56
57
# File 'lib/greenhouse/projects/project.rb', line 55

def to_arg
  Scripts::Argument.new(name, :summary => "#{title} (#{type.capitalize})")
end

#typeObject



51
52
53
# File 'lib/greenhouse/projects/project.rb', line 51

def type
  self.class.name.underscore.split('/').last
end