Sha256: 6863f1f063af56029d3aca25c3ed50f828f29b35057c891fad6c72e3edf293ae

Contents?: true

Size: 1.23 KB

Versions: 7

Compression:

Stored size: 1.23 KB

Contents

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? && gemfile_lock?
      definition = Bundler::Definition.build(@gemfile_path,
        @gemfile_lock_path, nil)
      @gems ||= definition.specs.map(&:name)
    end

    def repo_paths
      @repo_paths ||= begin
        files = `git ls-files`.split("\n")
        deleted_files = `git ls-files -d`.split("\n")
        files - deleted_files
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
shelly-0.2.6.pre lib/shelly/structure_validator.rb
shelly-0.2.5 lib/shelly/structure_validator.rb
shelly-0.2.4 lib/shelly/structure_validator.rb
shelly-0.2.3 lib/shelly/structure_validator.rb
shelly-0.2.2 lib/shelly/structure_validator.rb
shelly-0.2.1 lib/shelly/structure_validator.rb
shelly-0.2.0 lib/shelly/structure_validator.rb