Sha256: 54d59bc9c2a2af63bc3908920243483e8cd54a990845957d5ef0dd1bccb54a95

Contents?: true

Size: 1.4 KB

Versions: 15

Compression:

Stored size: 1.4 KB

Contents

require 'erb'

module Stove
  module Error
    class ErrorBinding
      def initialize(options = {})
        options.each do |key, value|
          instance_variable_set(:"@#{key}", value)
        end
      end

      def get_binding
        binding
      end
    end

    class StoveError < StandardError
      def initialize(options = {})
        @options  = options
        @filename = options.delete(:_template)

        super()
      end

      def message
        erb = ERB.new(File.read(template))
        erb.result(ErrorBinding.new(@options).get_binding)
      end
      alias_method :to_s, :message

      private

      def template
        class_name = self.class.to_s.split('::').last
        filename   = @filename || Util.underscore(class_name)
        Stove.root.join('templates', 'errors', "#{filename}.erb")
      end
    end

    class GitFailed < StoveError; end
    class MetadataNotFound < StoveError; end
    class ServerUnavailable < StoveError; end

    # Validations
    class ValidationFailed < StoveError; end
    class CommunityCategoryValidationFailed < ValidationFailed; end
    class CommunityKeyValidationFailed < ValidationFailed; end
    class CommunityUsernameValidationFailed < ValidationFailed; end
    class GitCleanValidationFailed < ValidationFailed; end
    class GitRepositoryValidationFailed < ValidationFailed; end
    class GitUpToDateValidationFailed < ValidationFailed; end
  end
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
stove-5.1.0 lib/stove/error.rb
stove-5.0.0 lib/stove/error.rb
stove-4.1.1 lib/stove/error.rb
stove-4.1.0 lib/stove/error.rb
stove-4.0.0 lib/stove/error.rb
stove-3.2.8 lib/stove/error.rb
wood-stove-3.2.9000 lib/stove/error.rb
stove-3.2.7 lib/stove/error.rb
stove-3.2.6 lib/stove/error.rb
stove-3.2.5 lib/stove/error.rb
stove-3.2.4 lib/stove/error.rb
stove-3.2.3 lib/stove/error.rb
stove-3.2.2 lib/stove/error.rb
stove-3.2.1 lib/stove/error.rb
stove-3.0.0 lib/stove/error.rb