Module: RubyRest::Tools

Included in:
Atom, Engine, RESTServlet, SimpleConfig
Defined in:
lib/rubyrest/tools.rb

Overview

This module provides a catalog of errors the application is supposed to throw.

Constant Summary collapse

ATOM_DATE_FORMAT =
"%Y-%m-%dT%H:%M:%SZ"
ERRORS =

Catalog of error messages, indexed by error number

{
  000 => "Missing configuration option",
  001 => "Unable to connect to database. Missing method",
  002 => "Unable to load schema. Missing method",
  003 => "Unable to create table",
  004 => "Please subclass and override",
  005 => "Sorry, configuration method did not return a valid database connection",
  006 => "Class was not property configured with its database connection (Sequel)",
  100 => "Request path and HTTP method are not compatible",
  200 => "No resource found for model and id",
  500 => "No service method found in model class"
}

Instance Method Summary collapse

Instance Method Details

#error(number, *params) ⇒ Object

Raises a new error. Resolves the specified number into a human readable message


65
66
67
# File 'lib/rubyrest/tools.rb', line 65

def error( number, *params )
  raise "\##{number}: #{ERRORS[number]}: #{params.join( ', ') }"
end

#format_atom_date(value) ⇒ Object


22
23
24
# File 'lib/rubyrest/tools.rb', line 22

def format_atom_date( value )
  nvl( value, Time.now ).strftime( ATOM_DATE_FORMAT )
end

#nvl(value, default) ⇒ Object


17
18
19
20
# File 'lib/rubyrest/tools.rb', line 17

def nvl( value, default )
  return value if value != nil
  return default
end

#parse_atom_date(value) ⇒ Object


26
27
28
# File 'lib/rubyrest/tools.rb', line 26

def parse_atom_date( value )
  Date.strptime( value, ATOM_DATE_FORMAT )
end

#to_class(modulename, model) ⇒ Object

Resolves the specified module name and model into a class, and returns it


32
33
34
# File 'lib/rubyrest/tools.rb', line 32

def to_class( modulename, model )
  Class.by_name( "#{modulename}::#{model.capitalize}" )
end

#to_gem_name(moduleprefix, modulename) ⇒ Object

Builds a gem name


37
38
39
40
# File 'lib/rubyrest/tools.rb', line 37

def to_gem_name( moduleprefix, modulename )
  return modulename if moduleprefix == nil
  return "#{moduleprefix}-#{modulename}"
end

#to_module_name(moduleprefix, modulename) ⇒ Object

Builds a fully qualified module name


43
44
45
46
# File 'lib/rubyrest/tools.rb', line 43

def to_module_name( moduleprefix, modulename )
  return modulename.capitalize if moduleprefix == nil
  return "#{moduleprefix.capitalize}::#{modulename.capitalize}"
end