Module: Greenhouse::Projects

Defined in:
lib/greenhouse/projects.rb,
lib/greenhouse/projects/gem.rb,
lib/greenhouse/projects/engine.rb,
lib/greenhouse/projects/project.rb,
lib/greenhouse/projects/collection.rb,
lib/greenhouse/projects/repository.rb,
lib/greenhouse/projects/application.rb

Defined Under Namespace

Classes: Application, Collection, Engine, Gem, Project, Repository

Constant Summary collapse

@@path =
nil
@@procfile =
nil
@@ignore_file =
nil
@@projects_file =
nil
@@dotenv =
nil
@@projects =
nil

Class Method Summary collapse

Class Method Details

.dotenvObject



75
76
77
78
# File 'lib/greenhouse/projects.rb', line 75

def self.dotenv
  return @@dotenv unless @@dotenv.nil?
  @@dotenv = Resources::DotenvFile.new("#{path}/.env")
end

.ignore_fileObject



60
61
62
63
# File 'lib/greenhouse/projects.rb', line 60

def self.ignore_file
  return @@ignore_file unless @@ignore_file.nil?
  @@ignore_file = Resources::IgnoreFile.new("#{path}/.ignore")
end

.ignoredObject



80
81
82
83
# File 'lib/greenhouse/projects.rb', line 80

def self.ignored
  return [] unless ignore_file.exists?
  ignore_file.ignored
end

.method_missing(meth, *args) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/greenhouse/projects.rb', line 19

def self.method_missing(meth, *args)
  if Project.subclasses.map { |subclass| subclass.name.pluralize.underscore.split("/").last.to_sym }.include?(meth.to_sym)
    projects.select { |proj| proj.class.name.pluralize.underscore.split("/").last.to_sym == meth.to_sym }
  else
    super
  end
end

.pathObject

Attempts to look for and returns the path of the root projects directory

Looks up the tree from the current directory, currently checking for a .projects file (this might change in the future).

If no projects path is found, the current directory is returned.



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/greenhouse/projects.rb', line 46

def self.path
  return @@path unless @@path.nil?
  dir = Dir.pwd
  while dir != "" do
    if File.exists?("#{dir}/.projects")
      @@path = dir
      return @@path
    end
    dir = dir.gsub(/\/[^\/]*\Z/,'')
  end
  @@path = Dir.pwd # if we haven't found a .projects file, this must be where they want to work
  @@path
end

.procfileObject



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

def self.procfile
  return @@procfile unless @@procfile.nil?
  @@procfile = Resources::Procfile.new("#{path}/Procfile")
end

.projectsObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/greenhouse/projects.rb', line 27

def self.projects
  @@projects = Collection.new
  return @@projects unless projects_file.exists?
  
  projects_file.projects.each do |name,project|
    type = (project.has_key?('type') ? project['type'] : 'project')
    projargs = Hash[project.merge({:remote => (project['remote'] || project['git'])}).map{ |k,v| [k.to_sym, v] }]
    classname = "Greenhouse::Projects::#{type.singularize.camelize}"
    @@projects << (defined?(classname.constantize) ? classname.constantize.new(name, projargs) : Greenhouse::Projects::Project.new(name, projargs))
  end
  @@projects
end

.projects_fileObject



65
66
67
68
# File 'lib/greenhouse/projects.rb', line 65

def self.projects_file
  return @@projects_file unless @@projects_file.nil?
  @@projects_file = Resources::ProjectsFile.new("#{path}/.projects")
end