Sha256: 64d11b940c9ca984edd3a4cf0baa5e7b3f771ade79e6b952f3fa9af6394ad030

Contents?: true

Size: 1.16 KB

Versions: 31

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal  = true

class Ree::ErrorBuilder
  def initialize(packages_facade)
    @packages_facade = packages_facade
  end

  def build(object, code, &proc)
    result = Ree::ErrorDsl.new.execute(object.klass, &proc)

    if result.is_a?(Ree::DomainError)
      object.klass.send(:remove_const, result.name) rescue nil
      result = Ree::ErrorDsl.new.execute(object.klass, &proc)
    end

    if !result.is_a?(Ree::ErrorDsl::ClassConstant)
      raise Ree::Error.new("invalid def_error usage", :invalid_dsl_usage)
    end

    object.klass.send(:remove_const, result.name) rescue nil

    object.klass.class_eval <<-ruby_eval, __FILE__, __LINE__ + 1
      class #{result.name} < Ree::DomainError
        attr_reader :code, :extra_code, :error_code, :package_name, :object_name

        def initialize(msg = nil, extra_code = nil)
          @code = #{code.inspect}
          @extra_code = extra_code
          @error_code = :#{Ree::StringUtils.underscore(result.name)}
          @package_name = :#{object.package_name}
          @object_name = :#{object.name}
          super(msg || #{result.message.inspect})
        end
      end
    ruby_eval

    result.name
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
ree-1.0.30 lib/ree/dsl/error_builder.rb
ree-1.0.29 lib/ree/dsl/error_builder.rb
ree-1.0.28 lib/ree/dsl/error_builder.rb
ree-1.0.27 lib/ree/dsl/error_builder.rb
ree-1.0.26 lib/ree/dsl/error_builder.rb
ree-1.0.25 lib/ree/dsl/error_builder.rb
ree-1.0.24 lib/ree/dsl/error_builder.rb
ree-1.0.23 lib/ree/dsl/error_builder.rb
ree-1.0.22 lib/ree/dsl/error_builder.rb
ree-1.0.21 lib/ree/dsl/error_builder.rb
ree-1.0.20 lib/ree/dsl/error_builder.rb
ree-1.0.19 lib/ree/dsl/error_builder.rb
ree-1.0.18 lib/ree/dsl/error_builder.rb
ree-1.0.17 lib/ree/dsl/error_builder.rb
ree-1.0.16 lib/ree/dsl/error_builder.rb
ree-1.0.15 lib/ree/dsl/error_builder.rb
ree-1.0.14 lib/ree/dsl/error_builder.rb
ree-1.0.13 lib/ree/dsl/error_builder.rb
ree-1.0.12 lib/ree/dsl/error_builder.rb
ree-1.0.11 lib/ree/dsl/error_builder.rb