lib/markable.rb in markable-0.0.8 vs lib/markable.rb in markable-0.1.0

- old
+ new

@@ -13,26 +13,26 @@ def self.set_models @@models = @@models.presence || ActiveRecord::Base.connection.tables.collect{ |t| t.classify rescue nil }.compact end - def self.add_markable markable + def self.add_markable(markable) @@markable_objects.push markable unless @@markable_objects.include? markable @@markables.push markable.name.to_sym unless @@markables.include? markable.name.to_sym create_methods @@marker_objects, [ markable ] end - def self.add_marker marker + def self.add_marker(marker) @@marker_objects.push marker unless @@marker_objects.include? marker @@markers.push marker.name.to_sym unless @@markers.include? marker.name.to_sym create_methods [ marker ], @@markable_objects end - def self.create_methods markers, markables + def self.create_methods(markers, markables) markables.try :each do |markable| markers.try :each do |marker| - markable.__markable_marks.each { |mark, options| + markable.__markable_marks.each do |mark, options| if options[:allowed_markers] == :all || options[:allowed_markers].include?(marker.marker_name) markable_name = markable.name.downcase method_name = "#{mark}_#{markable_name}".pluralize marker.class_eval %( def #{method_name} @@ -60,23 +60,23 @@ def #{marker.marker_name.to_s.pluralize}_have_marked_as_#{mark} self.have_marked_as_by(:#{mark}, #{marker.name}) end ) end - } + end end end end - def self.can_mark_or_raise? markers, markables, mark - Array.wrap(markers).all? { |marker_object| - Array.wrap(markables).all? { |markable| + def self.can_mark_or_raise?(markers, markables, mark) + Array.wrap(markers).all? do |marker_object| + Array.wrap(markables).all? do |markable| self.can_mark_object?(marker_object, markable, mark) - } - } + end + end end - def self.can_mark_object? marker_object, markable_object, mark + def self.can_mark_object?(marker_object, markable_object, mark) marker_name = marker_object.class.name.to_sym markable_name = markable_object.class.name.to_sym raise Markable::WrongMarkerType.new(marker_name) unless @@markers.include?(marker_name) raise Markable::WrongMarkableType.new(markable_name) unless @@markables.include?(markable_name) raise Markable::WrongMark.new(marker_object, markable_object, mark) unless markable_object.class.__markable_marks.include?(mark)