Sha256: 78b7a5b35339322c7f4265c3985f27d1f0f227004804374689d2673bb671d3b9

Contents?: true

Size: 1.56 KB

Versions: 21

Compression:

Stored size: 1.56 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") || gem?("shelly")
    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

21 entries across 21 versions & 1 rubygems

Version Path
shelly-0.4.18 lib/shelly/structure_validator.rb
shelly-0.4.17 lib/shelly/structure_validator.rb
shelly-0.4.16 lib/shelly/structure_validator.rb
shelly-0.4.15 lib/shelly/structure_validator.rb
shelly-0.4.14 lib/shelly/structure_validator.rb
shelly-0.4.13 lib/shelly/structure_validator.rb
shelly-0.4.12 lib/shelly/structure_validator.rb
shelly-0.4.11 lib/shelly/structure_validator.rb
shelly-0.4.10 lib/shelly/structure_validator.rb
shelly-0.4.9 lib/shelly/structure_validator.rb
shelly-0.4.8 lib/shelly/structure_validator.rb
shelly-0.4.7 lib/shelly/structure_validator.rb
shelly-0.4.6 lib/shelly/structure_validator.rb
shelly-0.4.5 lib/shelly/structure_validator.rb
shelly-0.4.4 lib/shelly/structure_validator.rb
shelly-0.4.2 lib/shelly/structure_validator.rb
shelly-0.4.1 lib/shelly/structure_validator.rb
shelly-0.4.0 lib/shelly/structure_validator.rb
shelly-0.4.0.pre lib/shelly/structure_validator.rb
shelly-0.3.8 lib/shelly/structure_validator.rb