Module: Markable::ActsAsMarker::MarkerInstanceMethods

Defined in:
lib/markable/acts_as_marker.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_sym, *args) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/markable/acts_as_marker.rb', line 24

def method_missing(method_sym, *args)
  Markable.models.each do |model_name|
    if method_sym.to_s =~ Regexp.new("^[\\w_]+_#{model_name.downcase.pluralize}$") ||
        method_sym.to_s =~ Regexp.new("^#{model_name.downcase.pluralize}_marked_as(_[\\w_]+)?$")
      model_name.constantize # ping model
      if self.methods.include? method_sym # method has appear
        return self.method(method_sym).call(*args) # call this method
      end
    end
  end
  super
rescue
  super
end

Instance Method Details

#remove_mark(mark, markables) ⇒ Object



46
47
48
49
50
51
# File 'lib/markable/acts_as_marker.rb', line 46

def remove_mark(mark, markables)
  Markable.can_mark_or_raise? self, markables, mark
  Array.wrap(markables).each do |markable|
    markable.unmark mark, :by => self
  end
end

#set_mark(mark, markables) ⇒ Object



39
40
41
42
43
44
# File 'lib/markable/acts_as_marker.rb', line 39

def set_mark(mark, markables)
  Array.wrap(markables).each do |markable|
    Markable.can_mark_or_raise? self, markable, mark
    markable.mark_as mark, self
  end
end