Sha256: 60e280abb92d86088aebd0fcf4eed40cc3e2a5917242542df3b3bcf44323d046

Contents?: true

Size: 1.54 KB

Versions: 23

Compression:

Stored size: 1.54 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 rakefile?
      repo_paths.include?("Rakefile")
    end

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

    def task?(name)
      tasks.include?("rake #{name}")
    end

    # Public: Check all requirements that app has to fulfill
    def valid?
      gemfile? && gemfile_lock? && gem?("rake") &&
        (gem?("thin") || gem?("puma")) && config_ru? &&
        rakefile? && task?("db:migrate") && task?("db:setup")
    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 tasks
      return [] unless rakefile?
      @loaded_tasks ||= %x(rake -P).split("\n")
    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

23 entries across 23 versions & 1 rubygems

Version Path
shelly-0.3.6 lib/shelly/structure_validator.rb
shelly-0.3.5 lib/shelly/structure_validator.rb
shelly-0.3.5.pre lib/shelly/structure_validator.rb
shelly-0.3.4 lib/shelly/structure_validator.rb
shelly-0.3.3 lib/shelly/structure_validator.rb
shelly-0.3.2 lib/shelly/structure_validator.rb
shelly-0.3.1 lib/shelly/structure_validator.rb
shelly-0.3.0 lib/shelly/structure_validator.rb
shelly-0.2.28 lib/shelly/structure_validator.rb
shelly-0.2.27 lib/shelly/structure_validator.rb
shelly-0.2.26 lib/shelly/structure_validator.rb
shelly-0.2.25 lib/shelly/structure_validator.rb
shelly-0.2.24 lib/shelly/structure_validator.rb
shelly-0.2.23 lib/shelly/structure_validator.rb
shelly-0.2.22 lib/shelly/structure_validator.rb
shelly-0.2.21 lib/shelly/structure_validator.rb
shelly-0.2.20 lib/shelly/structure_validator.rb
shelly-0.2.19 lib/shelly/structure_validator.rb
shelly-0.2.18 lib/shelly/structure_validator.rb
shelly-0.2.17 lib/shelly/structure_validator.rb