Class: Project
- Inherits:
-
Object
show all
- Defined in:
- lib/soundcheck/project.rb
Defined Under Namespace
Classes: UnknownFramework, UnknownLanguage
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(root) ⇒ Project
Returns a new instance of Project.
10
11
12
|
# File 'lib/soundcheck/project.rb', line 10
def initialize(root)
self.root = root
end
|
Instance Attribute Details
#root ⇒ Object
Returns the value of attribute root.
8
9
10
|
# File 'lib/soundcheck/project.rb', line 8
def root
@root
end
|
Instance Method Details
#execute(command) ⇒ Object
63
64
65
66
67
68
69
|
# File 'lib/soundcheck/project.rb', line 63
def execute(command)
logger.debug "Executing #{command}"
Dir.chdir(root) do
output = `#{command}`
[output, $?]
end
end
|
#file_contents(filename) ⇒ Object
30
31
32
|
# File 'lib/soundcheck/project.rb', line 30
def file_contents(filename)
File.read(File.expand_path(File.join(root, filename)))
end
|
#frameworks ⇒ Object
53
54
55
56
57
58
59
60
61
|
# File 'lib/soundcheck/project.rb', line 53
def frameworks
detected_frameworks = language.frameworks.map do |framework_class|
framework_class.new(self)
end
logger.debug "Detected your frameworks: #{detected_frameworks}"
raise UnknownFramework if detected_frameworks.empty?
return detected_frameworks
end
|
#has_dir?(dirname) ⇒ Boolean
14
15
16
17
18
|
# File 'lib/soundcheck/project.rb', line 14
def has_dir?(dirname)
Dir.chdir(root) do
Dir.exist?(dirname)
end
end
|
#has_file?(filename) ⇒ Boolean
20
21
22
23
24
|
# File 'lib/soundcheck/project.rb', line 20
def has_file?(filename)
Dir.chdir(root) do
not Dir.glob(filename).empty?
end
end
|
#has_files?(*paths) ⇒ Boolean
26
27
28
|
# File 'lib/soundcheck/project.rb', line 26
def has_files?(*paths)
paths.any? { |path| has_file?(path) }
end
|
#language ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/soundcheck/project.rb', line 34
def language
case
when has_file?("Gemfile")
logger.debug "You have a Gemfile, so I think this is Ruby."
return Languages::Ruby.new(self)
when has_file?("Rakefile")
logger.debug "You have a Rakefile, so I think this is Ruby."
return Languages::Ruby.new(self)
when has_file?("*.gemspec")
logger.debug "You have a gemspec, so I think this is Ruby."
return Languages::Ruby.new(self)
when has_file?("package.json")
logger.debug "You have a package.json, so I think this is NodeJS."
return Languages::NodeJS.new(self)
else
raise UnknownLanguage
end
end
|