Class: Detroit::Project

Inherits:
Object show all
Defined in:
lib/detroit/project.rb

Overview

Base class for more specific Project types.

Direct Known Subclasses

RubyProject

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ Pathname

Initialize new instance of Project.

Parameters:

  • root (String, Pathname)

    Root directory of project.



48
49
50
51
# File 'lib/detroit/project.rb', line 48

def initialize(root)
  @root = Pathname.new(root)
  @log  = @root + 'log'
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(s, *a, &b) ⇒ Object

If method is missing see if it is a piece of metadata.



81
82
83
84
85
# File 'lib/detroit/project.rb', line 81

def method_missing(s, *a, &b)
  super(s, *a, &b) unless a.empty?
  super(s, *a, &b) if block_given?
  .send(s)
end

Instance Attribute Details

#logObject (readonly)

Log directory. By defaul this is ‘root/log/`.



59
60
61
# File 'lib/detroit/project.rb', line 59

def log
  @log
end

#rootPathname (readonly)

Root directory.

Returns:

  • (Pathname)


56
57
58
# File 'lib/detroit/project.rb', line 56

def root
  @root
end

Class Method Details

.factory(root) ⇒ Project

Get a new project instance based on criteria of the project. For instance a project with a ‘*.gemspec` is recognized as a Ruby project and thus returns an instance of RubyProject.

Returns:



34
35
36
37
38
39
40
# File 'lib/detroit/project.rb', line 34

def self.factory(root)
  if RubyProject.project?(root)
    RubyProject.new(root)
  else
    Project.new(root)
  end
end

.lookupObject



20
21
22
23
24
25
26
27
# File 'lib/detroit/project.rb', line 20

def self.lookup
  dir = Dir.pwd
  while dir != '/' #&& dir != $HOME
    return new(dir) if project?(dir)
    dir = File.dirname(dir)
  end
  return nil
end

.rootObject

FIXME: Lookup root directory. How?



15
16
17
# File 'lib/detroit/project.rb', line 15

def self.root
  Dir.pwd 
end

Instance Method Details

#configConfig

Detroit configuration for project.

Returns:

  • (Config)


64
65
66
# File 'lib/detroit/project.rb', line 64

def config
  @config ||= Config.new(root)
end

#metadataIndexer::Metadata

Access to project metadata. Metadata is handled by Indexer. If a specific project type has different needs then override this method. The return value should work akin to an OpenStruct instance, and if possible it should respond to ‘#to_h` method.

Returns:

  • (Indexer::Metadata)


76
77
78
# File 'lib/detroit/project.rb', line 76

def 
  @metadata ||= Indexer::Metadata.open(root)
end