Sha256: d943a7dbca43aab5fa60da42c8d4954fa41c8d1670b6dd1ba530bb99b651c192

Contents?: true

Size: 1.41 KB

Versions: 30

Compression:

Stored size: 1.41 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? && 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(".")
        # Select files from repo which are unchanged, added or modified
        # and then return their paths
        repo.status.files.map(&:last).select { |status|
          status.type.nil? || status.type == 'A' || status.type == 'M'
        }.map(&:path)
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
shelly-0.1.40 lib/shelly/structure_validator.rb
shelly-0.1.39 lib/shelly/structure_validator.rb
shelly-0.1.38 lib/shelly/structure_validator.rb
shelly-0.1.37.pre lib/shelly/structure_validator.rb
shelly-0.1.36 lib/shelly/structure_validator.rb
shelly-0.1.35 lib/shelly/structure_validator.rb
shelly-0.1.34 lib/shelly/structure_validator.rb
shelly-0.1.34.pre lib/shelly/structure_validator.rb
shelly-0.1.33 lib/shelly/structure_validator.rb
shelly-0.1.32 lib/shelly/structure_validator.rb
shelly-0.1.31 lib/shelly/structure_validator.rb
shelly-0.1.30 lib/shelly/structure_validator.rb
shelly-0.1.29 lib/shelly/structure_validator.rb
shelly-0.1.28 lib/shelly/structure_validator.rb
shelly-0.1.27 lib/shelly/structure_validator.rb
shelly-0.1.26 lib/shelly/structure_validator.rb
shelly-0.1.25 lib/shelly/structure_validator.rb
shelly-0.1.24 lib/shelly/structure_validator.rb
shelly-0.1.24.pre2 lib/shelly/structure_validator.rb
shelly-0.1.24.pre lib/shelly/structure_validator.rb