Sha256: 43a2497559b967167ade75f513c2d1eb0b68aefae44cba5881e8d6b981f57e7b

Contents?: true

Size: 1.64 KB

Versions: 5

Compression:

Stored size: 1.64 KB

Contents

require 'soundcheck/logging'
require 'soundcheck/languages'

class Project
  class UnknownLanguage < StandardError; end
  class UnknownFramework < StandardError; end

  attr_accessor :root

  def initialize(root)
    self.root = root
  end

  def has_dir?(dirname)
    Dir.chdir(root) do
      Dir.exist?(dirname)
    end
  end

  def has_file?(filename)
    Dir.chdir(root) do
      not Dir.glob(filename).empty?
    end
  end

  def has_files?(*paths)
    paths.any? { |path| has_file?(path) }
  end

  def file_contents(filename)
    File.read(File.expand_path(File.join(root, filename)))
  end

  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
  
  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

  def execute(command)
    logger.debug "Executing #{command}"
    Dir.chdir(root) do
      output = `#{command}`
      [output, $?]
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
soundcheck-0.4.0 lib/soundcheck/project.rb
soundcheck-0.3.0 lib/soundcheck/project.rb
soundcheck-0.2.4.beta1 lib/soundcheck/project.rb
soundcheck-0.2.3 lib/soundcheck/project.rb
soundcheck-0.2.2 lib/soundcheck/project.rb