Module: AWS::Core::LazyErrorClasses
- Included in:
- AutoScaling::Errors, AWS::CloudFormation::Errors, AWS::CloudFront::Errors, AWS::CloudSearch::Errors, AWS::CloudWatch::Errors, DataPipeline::Errors, DynamoDB::Errors, EC2::Errors, ELB::Errors, EMR::Errors, ElastiCache::Errors, ElasticBeanstalk::Errors, ElasticTranscoder::Errors, Glacier::Errors, IAM::Errors, ImportExport::Errors, OpsWorks::Errors, RDS::Errors, Redshift::Errors, Route53::Errors, S3::Errors, SNS::Errors, SQS::Errors, STS::Errors, SimpleEmailService::Errors, SimpleWorkflow::Errors, StorageGateway::Errors
- Defined in:
- lib/aws/core/lazy_error_classes.rb
Overview
Provides lazy creation of error classes via #const_missing.
Extend this module provides 3 benefits to another module:
-
A method that accepts strings and returns error classes.
-
Thread-safe dynamic error class creation via #const_missing
-
An error grammar for parsing AWS xml errors
Here is an example of how it works:
Class Foo
module Errors
extend AWS::Core::LazyErrorClasses
end
end
Foo::Errors.error_class('NoSuchKey')
#=> Foo::Errors::NoSuckKey
Foo::Errors.error_class('Nested.Error.Klasses')
#=> Foo::Errors::Nested::Error::Klasses
The errors returned from #error_class are subclasses of Errors::Base.
Constant Summary collapse
- BASE_ERROR_GRAMMAR =
This grammar parses the defualt AWS XML error format
XML::Grammar.customize do element("Error") do ignore end end
Instance Method Summary collapse
-
#const_missing(constant) ⇒ nil
Defines a new error class.
-
#error_class(code) ⇒ Class
Converts the error code into an error class constant.
Instance Method Details
#const_missing(constant) ⇒ nil
Defines a new error class.
68 69 70 71 72 |
# File 'lib/aws/core/lazy_error_classes.rb', line 68 def const_missing constant const_missing_mutex.synchronize do const_set(constant, Class.new(Errors::Base) { extend LazyErrorClasses }) end end |
#error_class(code) ⇒ Class
83 84 85 |
# File 'lib/aws/core/lazy_error_classes.rb', line 83 def error_class code module_eval("#{self}::#{code.gsub('.Range','Range').gsub(".","::")}") end |