Module: MetaRuby::DSLs::FindThroughMethodMissing

Defined in:
lib/metaruby/dsls/find_through_method_missing.rb

Overview

Common definition of #respond_to_missing? and #method_missing to be used in conjunction with find_through_method_missing and has_through_method_missing?

Examples:

resolve ‘event’ objects using method_missing

class Task
   # Tests if this task has an event by this name
   #
   # @param [String] name
   # @return [Boolean]
   def has_event?(name)
   end

   # Finds an event by name
   #
   # @param [String] name
   # @return [Object,nil] the found event, or nil if there is no
   #   event by this name
   def find_event(name)
   end

   include MetaRuby::DSLs::FindThroughMethodMissing

   # Check if the given method matches a find object
   def has_through_method_missing?(m)
     MetaRuby::DSLs.has_through_method_missing?(
        self, m, '_event' => :has_event?) || super
   end

   # Check if the given method matches a find object
   def find_through_method_missing(m, args)
     MetaRuby::DSLs.find_through_method_missing(
        self, m, args, '_event' => :find_event) || super
   end
end

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args) ⇒ Object

Resolves the given method using #find_through_method_missing



58
59
60
# File 'lib/metaruby/dsls/find_through_method_missing.rb', line 58

def method_missing(m, *args)
    find_through_method_missing(m, args) || super
end

Instance Method Details

#find_through_method_missing(m, args) ⇒ Object

Empty implementation of find_through_method_missing to allow for classes to call ‘super’



49
50
# File 'lib/metaruby/dsls/find_through_method_missing.rb', line 49

def find_through_method_missing(m, args)
end

#has_through_method_missing?(m) ⇒ Boolean

Empty implementation of has_through_method_missing? to allow for classes to call ‘super’

Returns:

  • (Boolean)


44
45
# File 'lib/metaruby/dsls/find_through_method_missing.rb', line 44

def has_through_method_missing?(m)
end

#respond_to_missing?(m, include_private) ⇒ Boolean

Resolves the given method using #has_through_method_missing?

Returns:

  • (Boolean)


53
54
55
# File 'lib/metaruby/dsls/find_through_method_missing.rb', line 53

def respond_to_missing?(m, include_private)
    has_through_method_missing?(m) || super
end