Class: Lafcadio::ObjectStore::MethodDispatch
- Inherits:
-
Object
- Object
- Lafcadio::ObjectStore::MethodDispatch
- Defined in:
- lib/lafcadio/objectStore.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#symbol ⇒ Object
readonly
Returns the value of attribute symbol.
Instance Method Summary collapse
- #dispatch_get_method ⇒ Object
- #dispatch_get_plural ⇒ Object
- #dispatch_get_plural_by_query_block ⇒ Object
- #dispatch_get_plural_by_query_block_or_search_term(searchTerm, fieldName) ⇒ Object
- #dispatch_get_singular ⇒ Object
-
#initialize(orig_method, maybe_proc, *orig_args) ⇒ MethodDispatch
constructor
A new instance of MethodDispatch.
- #method_name_after_get ⇒ Object
- #raise_no_method_error ⇒ Object
Constructor Details
#initialize(orig_method, maybe_proc, *orig_args) ⇒ MethodDispatch
Returns a new instance of MethodDispatch.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/lafcadio/objectStore.rb', line 12 def initialize( orig_method, maybe_proc, *orig_args ) @orig_method = orig_method @maybe_proc = maybe_proc @orig_args = orig_args @methodName = orig_method.id2name if @methodName =~ /^get(.*)$/ dispatch_get_method else raise_no_method_error end end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
10 11 12 |
# File 'lib/lafcadio/objectStore.rb', line 10 def args @args end |
#symbol ⇒ Object (readonly)
Returns the value of attribute symbol.
10 11 12 |
# File 'lib/lafcadio/objectStore.rb', line 10 def symbol @symbol end |
Instance Method Details
#dispatch_get_method ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/lafcadio/objectStore.rb', line 63 def dispatch_get_method begin dispatch_get_singular rescue CouldntMatchObjectTypeError objectTypeName = English.singular( method_name_after_get ) begin @domain_class = DomainObject. getObjectTypeFromString( objectTypeName ) dispatch_get_plural rescue CouldntMatchObjectTypeError raise_no_method_error end end end |
#dispatch_get_plural ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/lafcadio/objectStore.rb', line 24 def dispatch_get_plural if @orig_args.size == 0 && @maybe_proc.nil? @symbol = :getAll @args = [ @domain_class ] else searchTerm = @orig_args[0] fieldName = @orig_args[1] if searchTerm.nil? && @maybe_proc.nil? && fieldName.nil? msg = "ObjectStore\##{ @orig_method } needs a field name as its " + "second argument if its first argument is nil" raise( ArgumentError, msg, caller ) end dispatch_get_plural_by_query_block_or_search_term( searchTerm, fieldName ) end end |
#dispatch_get_plural_by_query_block ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/lafcadio/objectStore.rb', line 41 def dispatch_get_plural_by_query_block inferrer = Query::Inferrer.new( @domain_class ) { |obj| @maybe_proc.call( obj ) } @symbol = :getSubset @args = [ inferrer.execute ] end |
#dispatch_get_plural_by_query_block_or_search_term(searchTerm, fieldName) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/lafcadio/objectStore.rb', line 49 def dispatch_get_plural_by_query_block_or_search_term( searchTerm, fieldName ) if !@maybe_proc.nil? && searchTerm.nil? dispatch_get_plural_by_query_block elsif @maybe_proc.nil? && ( !( searchTerm.nil? && fieldName.nil? ) ) @symbol = :getFiltered @args = [ @domain_class.name, searchTerm, fieldName ] else raise( ArgumentError, "Shouldn't send both a query block and a search term", caller ) end end |
#dispatch_get_singular ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/lafcadio/objectStore.rb', line 78 def dispatch_get_singular objectType = DomainObject. getObjectTypeFromString( method_name_after_get ) if @orig_args[0].class <= Integer @symbol = :get @args = [ objectType, @orig_args[0] ] elsif @orig_args[0].class <= DomainObject @symbol = :getMapObject @args = [ objectType, @orig_args[0], @orig_args[1] ] end end |
#method_name_after_get ⇒ Object
90 91 92 93 |
# File 'lib/lafcadio/objectStore.rb', line 90 def method_name_after_get @orig_method.id2name =~ /^get(.*)$/ $1 end |
#raise_no_method_error ⇒ Object
95 96 97 |
# File 'lib/lafcadio/objectStore.rb', line 95 def raise_no_method_error raise( NoMethodError, "undefined method '#{ @methodName }'", caller ) end |