Class ArsModels::Base
In: lib/ars_models/base.rb
Parent: Object

TODO: Document ArsModels::Base

Methods

Public Class methods

TODO: Document ArsModels::Base#initialize

[Source]

    # File lib/ars_models/base.rb, line 7
 7:     def initialize(*args)
 8:       # Pop the last argument if it is an options hash

 9:       options = args.last.is_a?(::Hash) ? args.pop : {}
10: 
11:       # Execute the generation or building of the object based on the arguments provided

12:       case args.length
13:         # If there is not a source JAPI object, build from the options

14:         when 0 then build(options)
15:         # If there is a source JAPI object, generate from the object

16:         when 1 then generate(args[0], options)
17:         # If there was more than one argument, raise an invalid argument error

18:         else raise "Invalid #{self.class.name} constructor arguments."
19:       end
20:     end

TODO: Document ArsModels::Base.validate_options

[Source]

    # File lib/ars_models/base.rb, line 23
23:     def self.validate_options(hash, options={})
24:       # Default the option values

25:       options[:required] ||= []
26:       options[:optional] ||= []
27: 
28:       # Get the name of the calling method

29:       last_call = caller[0]
30:       calling_method = last_call[last_call.rindex('`')+1..-2].inspect
31: 
32:       # Check for required options

33:       missing_keys = options[:required] - hash.keys
34:       raise(ArgumentError, "Missing key(s): #{missing_keys.collect {|key| key.inspect}.join(", ")} for method #{calling_method}") unless missing_keys.empty?
35: 
36:       # Verify there are no unexpected keys

37:       unknown_keys = hash.keys - [options[:required] + options[:optional]].flatten
38:       raise(ArgumentError, "Unknown key(s): #{unknown_keys.collect {|key| key.inspect}.join(", ")} for method #{calling_method}") unless unknown_keys.empty?
39:     end

Public Instance methods

TODO: Document ArsModels::Base#build Build an ArsModels object manually

[Source]

    # File lib/ars_models/base.rb, line 63
63:     def build(*args)
64:       raise "Method 'build' not implemented for #{self.class.name}"
65:     end

TODO: Document ArsModels::Base#generate Generate an ArsModels object from a source JAPI model

[Source]

    # File lib/ars_models/base.rb, line 69
69:     def generate(*args)
70:       raise "Method 'generate' not implemented for #{self.class.name}"
71:     end

TODO: Document ArsModels::Base#validate_options

[Source]

    # File lib/ars_models/base.rb, line 42
42:     def validate_options(hash, options={})
43:       # Default the option values

44:       options[:required] ||= []
45:       options[:optional] ||= []
46: 
47:       # Get the name of the calling method

48:       last_call = caller[0]
49:       calling_method = last_call[last_call.rindex('`')+1..-2].inspect
50: 
51:       # Check for required options

52:       missing_keys = options[:required] - hash.keys
53:       raise(ArgumentError, "Missing key(s): #{missing_keys.collect {|key| key.inspect}.join(", ")} for method #{calling_method}") unless missing_keys.empty?
54: 
55:       # Verify there are no unexpected keys

56:       unknown_keys = hash.keys - [options[:required] + options[:optional]].flatten
57:       raise(ArgumentError, "Unknown key(s): #{unknown_keys.collect {|key| key.inspect}.join(", ")} for method #{calling_method}") unless unknown_keys.empty?
58: 
59:     end

[Validate]