Sha256: 373233c958167993581c61e24753bec00e0a81be311af63a8e241cc675890871

Contents?: true

Size: 448 Bytes

Versions: 15

Compression:

Stored size: 448 Bytes

Contents

# frozen_string_literal: true

class Ree::ErrorDsl
  def execute(klass, &proc)
    self.class.instance_exec(&proc)
  rescue NameError => e
    proc
      .binding
      .eval("#{e.name} = Ree::ErrorDsl::ClassConstant.new('#{e.name}')")

    retry
  end

  class ClassConstant
    attr_reader :name, :message

    def initialize(name)
      @name = name
      @message = nil
    end

    def [](msg)
      @message = msg
      self
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
ree-1.0.47 lib/ree/dsl/error_dsl.rb
ree-1.0.46 lib/ree/dsl/error_dsl.rb
ree-1.0.45 lib/ree/dsl/error_dsl.rb
ree-1.0.44 lib/ree/dsl/error_dsl.rb
ree-1.0.43 lib/ree/dsl/error_dsl.rb
ree-1.0.42 lib/ree/dsl/error_dsl.rb
ree-1.0.41 lib/ree/dsl/error_dsl.rb
ree-1.0.40 lib/ree/dsl/error_dsl.rb
ree-1.0.39 lib/ree/dsl/error_dsl.rb
ree-1.0.38 lib/ree/dsl/error_dsl.rb
ree-1.0.37 lib/ree/dsl/error_dsl.rb
ree-1.0.36 lib/ree/dsl/error_dsl.rb
ree-1.0.35 lib/ree/dsl/error_dsl.rb
ree-1.0.34 lib/ree/dsl/error_dsl.rb
ree-1.0.33 lib/ree/dsl/error_dsl.rb