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
- #camel_case_method_name ⇒ Object
- #dispatch(object_store) ⇒ Object
- #dispatch_all ⇒ Object
- #dispatch_domain_class_get(searchTerm, fieldName) ⇒ Object
- #dispatch_get_map_object(domain_class) ⇒ Object
- #dispatch_method ⇒ Object
- #dispatch_plural ⇒ Object
- #dispatch_plural_by_query_block ⇒ Object
- #dispatch_singular ⇒ Object
-
#initialize(orig_method, *other_args) ⇒ MethodDispatch
constructor
A new instance of MethodDispatch.
- #raise_plural_cant_have_both_query_block_and_search_term ⇒ Object
- #raise_plural_needs_field_arg_if_first_arg_nil ⇒ Object
Constructor Details
#initialize(orig_method, *other_args) ⇒ MethodDispatch
Returns a new instance of MethodDispatch.
714 715 716 717 718 719 720 |
# File 'lib/lafcadio/objectStore.rb', line 714 def initialize( orig_method, *other_args ) @orig_method = orig_method @orig_args = other_args @maybe_proc = @orig_args.shift if @orig_args.size > 0 @methodName = orig_method.id2name dispatch_method end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
712 713 714 |
# File 'lib/lafcadio/objectStore.rb', line 712 def args @args end |
#symbol ⇒ Object (readonly)
Returns the value of attribute symbol.
712 713 714 |
# File 'lib/lafcadio/objectStore.rb', line 712 def symbol @symbol end |
Instance Method Details
#camel_case_method_name ⇒ Object
722 723 724 |
# File 'lib/lafcadio/objectStore.rb', line 722 def camel_case_method_name @orig_method.id2name.underscore_to_camel_case end |
#dispatch(object_store) ⇒ Object
726 727 728 729 |
# File 'lib/lafcadio/objectStore.rb', line 726 def dispatch( object_store ) target = ( @target or object_store ) target.send( @symbol, *@args ) end |
#dispatch_all ⇒ Object
731 732 733 734 |
# File 'lib/lafcadio/objectStore.rb', line 731 def dispatch_all @symbol = :all @args = [ @domain_class ] end |
#dispatch_domain_class_get(searchTerm, fieldName) ⇒ Object
736 737 738 739 740 |
# File 'lib/lafcadio/objectStore.rb', line 736 def dispatch_domain_class_get( searchTerm, fieldName ) @symbol = :get @args = [ searchTerm, fieldName ] @target = @domain_class end |
#dispatch_get_map_object(domain_class) ⇒ Object
742 743 744 745 |
# File 'lib/lafcadio/objectStore.rb', line 742 def dispatch_get_map_object( domain_class ) @symbol = :get_map_object @args = [ domain_class, @orig_args[0], @orig_args[1] ] end |
#dispatch_method ⇒ Object
772 773 774 775 776 777 778 779 780 781 782 |
# File 'lib/lafcadio/objectStore.rb', line 772 def dispatch_method unless ( dispatch_singular ) domain_class_name = camel_case_method_name.singular begin @domain_class = Module.by_name domain_class_name dispatch_plural rescue NameError # skip it end end end |
#dispatch_plural ⇒ Object
747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 |
# File 'lib/lafcadio/objectStore.rb', line 747 def dispatch_plural if @orig_args.size == 0 && @maybe_proc.nil? dispatch_all else searchTerm, fieldName = @orig_args[0..1] if searchTerm.nil? && @maybe_proc.nil? && fieldName.nil? raise_plural_needs_field_arg_if_first_arg_nil elsif !@maybe_proc.nil? && searchTerm.nil? dispatch_plural_by_query_block elsif @maybe_proc.nil? && ( !( searchTerm.nil? && fieldName.nil? ) ) dispatch_domain_class_get( searchTerm, fieldName ) else raise_plural_cant_have_both_query_block_and_search_term end end end |
#dispatch_plural_by_query_block ⇒ Object
764 765 766 767 768 769 770 |
# File 'lib/lafcadio/objectStore.rb', line 764 def dispatch_plural_by_query_block inferrer = Query::Inferrer.new( @domain_class ) { |obj| @maybe_proc.call( obj ) } @symbol = :query @args = [ inferrer.execute ] end |
#dispatch_singular ⇒ Object
784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 |
# File 'lib/lafcadio/objectStore.rb', line 784 def dispatch_singular begin d_class_name = @orig_method.id2name.underscore_to_camel_case domain_class = Module.by_name d_class_name if @orig_args[0].class <= Integer @symbol = :get @args = [ domain_class, @orig_args[0] ] elsif @orig_args[0].class <= DomainObject dispatch_get_map_object domain_class elsif @orig_args.empty? @symbol = :get end true rescue NameError false end end |
#raise_plural_cant_have_both_query_block_and_search_term ⇒ Object
808 809 810 811 812 813 |
# File 'lib/lafcadio/objectStore.rb', line 808 def raise_plural_cant_have_both_query_block_and_search_term raise( ArgumentError, "Shouldn't send both a query block and a search term", caller ) end |
#raise_plural_needs_field_arg_if_first_arg_nil ⇒ Object
802 803 804 805 806 |
# File 'lib/lafcadio/objectStore.rb', line 802 def raise_plural_needs_field_arg_if_first_arg_nil msg = "ObjectStore\##{ @orig_method } needs a field name as its " + "second argument if its first argument is nil" raise( ArgumentError, msg, caller ) end |