Exception: Trax::Core::Errors::Base

Inherits:
StandardError
  • Object
show all
Defined in:
lib/trax/core/errors.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**_attributes) ⇒ Base

Returns a new instance of Base.



75
76
77
78
79
# File 'lib/trax/core/errors.rb', line 75

def initialize(**_attributes)
  @arguments_instance = self.class.permitted_arguments_klass.new(_attributes)

  super(message)
end

Instance Attribute Details

#arguments_instanceObject (readonly)

Returns the value of attribute arguments_instance.



73
74
75
# File 'lib/trax/core/errors.rb', line 73

def arguments_instance
  @arguments_instance
end

Class Method Details

.argument(method_name, *args) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/trax/core/errors.rb', line 48

def self.argument(method_name, *args)
  permitted_arguments_klass.property(method_name, *args)

  define_method(method_name) do
    arguments_instance.__send__(method_name)
  end
end

.error_arguments_klassObject

if no properties have been defined using argument method, wrap in Mash



69
70
71
# File 'lib/trax/core/errors.rb', line 69

def self.error_arguments_klass
  @error_arguments_klass ||= (permitted_arguments_klass.properties.length) ? permitted_arguments_klass : ::Hashie::Mash
end

.inherited(subklass) ⇒ Object

on inherit of Trax::Core::Errors::Base, inherit from arguments class above to provide simple dsl options / typecasting and stuff to our errors.



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/trax/core/errors.rb', line 36

def self.inherited(subklass)
  subklass.class_eval do
    arguments_class_name = "#{subklass.name.demodulize}Arguments"
    arguments_klass = const_set(arguments_class_name, ::Class.new(::Trax::Core::Errors::Arguments)) unless const_defined?(arguments_class_name)
    @_permitted_arguments_klass = arguments_klass
    @_permitted_arguments = arguments_klass.new

    attr_reader :_permitted_arguments
    attr_reader :_permitted_arguments_klass
  end
end

.message(&block) ⇒ Object



64
65
66
# File 'lib/trax/core/errors.rb', line 64

def self.message(&block)
  self._message = block
end

.permitted_argumentsObject



60
61
62
# File 'lib/trax/core/errors.rb', line 60

def self.permitted_arguments
  @_permitted_arguments
end

.permitted_arguments_klassObject



56
57
58
# File 'lib/trax/core/errors.rb', line 56

def self.permitted_arguments_klass
  @_permitted_arguments_klass
end

Instance Method Details

#messageObject



81
82
83
# File 'lib/trax/core/errors.rb', line 81

def message
  self.instance_eval(&self.class._message)
end