Sha256: 5fe58380669f61e6ed19782a9cb3ed5b9a79948523755f3b2262573e209b9245

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

require 'grit'
require 'bundler'

module Shelly
  class StructureValidator
    def initialize
      @gemfile_path = "Gemfile"
      @gemfile_lock_path = "Gemfile.lock"
    end

    def gemfile?
      repo_paths.include?(@gemfile_path)
    end

    def gemfile_lock?
      repo_paths.include?(@gemfile_lock_path)
    end

    def config_ru?
      repo_paths.include?("config.ru")
    end

    def gem?(name)
      gems.include?(name)
    end

    # Public: Check all requirements that app has to fulfill
    def valid?
      gemfile? && gemfile_lock? && gem?("thin") &&
        gem?("rake") && config_ru?
    end

    def invalid?
      !valid?
    end

    # Public: Check if there are any warnings regarding app
    # structure, these warning don't prevent from deploying
    # to shelly
    def warnings?
      !gem?("shelly-dependencies")
    end

    private

    def gems
      return [] unless gemfile? or gemfile_lock?
      definition = Bundler::Definition.build(@gemfile_path,
        @gemfile_lock_path, nil)
      @gems ||= definition.specs.map(&:name)
    end

    def repo_paths
      @repo_paths ||= begin
        repo = Grit::Repo.new(".")
        repo.status.map(&:path)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shelly-0.1.14 lib/shelly/structure_validator.rb