ref: master
plugins/open_graph/lib/open_graph_plugin/attach_stories.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
require_dependency 'open_graph_plugin/stories' # This is used when ActionTracker is not compartible with the way module OpenGraphPlugin::AttachStories module ClassMethods def open_graph_attach_stories options={} if stories = Array(options[:only]) callbacks = {} stories.each do |story| defs = OpenGraphPlugin::Stories::Definitions[story] Array(defs[:on]).each do |on| callbacks[on] ||= [] callbacks[on] << story end end else klass = self.name callbacks = OpenGraphPlugin::Stories::ModelStories[klass.to_sym] return if callbacks.blank? end callbacks.each do |on, stories| # subclasses may override this, but the callback is called only once method = "open_graph_publish_after_#{on}" self.send "after_#{on}", method # buggy with rails 3.2 #self.send "after_commit", method, on: on define_method method do OpenGraphPlugin::Stories.publish self, stories end end end end module InstanceMethods end end |