Class: RestMyCase::Context::Base

Inherits:
OpenStruct
  • Object
show all
Includes:
ActiveModel::Serialization
Defined in:
lib/rest_my_case/context/base.rb

Direct Known Subclasses

Status

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.error_classObject



13
14
15
# File 'lib/rest_my_case/context/base.rb', line 13

def self.error_class
  Errors::Base
end

.schema_validator_classObject



17
18
19
# File 'lib/rest_my_case/context/base.rb', line 17

def self.schema_validator_class
  SchemaValidator::Base
end

Instance Method Details

#errorsObject



33
34
35
# File 'lib/rest_my_case/context/base.rb', line 33

def errors
  @errors ||= self.class.error_class.new(self)
end

#to_hashObject



25
26
27
# File 'lib/rest_my_case/context/base.rb', line 25

def to_hash
  Marshal.load Marshal.dump(attributes)
end

#valid?Boolean Also known as: ok?

Returns:

  • (Boolean)


37
38
39
# File 'lib/rest_my_case/context/base.rb', line 37

def valid?
  errors.empty?
end

#validate_schema(schema) ⇒ Object



29
30
31
# File 'lib/rest_my_case/context/base.rb', line 29

def validate_schema(schema)
  self.class.schema_validator_class.new(self).validate(schema)
end

#values_at(*keys) ⇒ Object



21
22
23
# File 'lib/rest_my_case/context/base.rb', line 21

def values_at(*keys)
  attributes.values_at(*keys)
end