lib/scribd_fu.rb in scribd_fu-2.0.10 vs lib/scribd_fu.rb in scribd_fu-2.0.11

- old
+ new

@@ -1,8 +1,8 @@ module ScribdFu - ConfigPath = "#{::Rails.root.to_s}/config/scribd_fu.yml".freeze + ConfigPath = "config/scribd_fu.yml".freeze # A list of content types supported by iPaper. ContentTypes = [ 'application/pdf', 'application/msword', @@ -78,14 +78,15 @@ document.destroy end # Read, store, and return the ScribdFu config file's contents def config - raise ScribdFuError, "#{ConfigPath} does not exist" unless File.file?(ConfigPath) + path = defined?(Rails) ? File.join(Rails.root, ConfigPath) : ConfigPath + raise ScribdFuError, "#{path} does not exist" unless File.file?(path) # Load the config file and strip any whitespace from the values - @config ||= YAML.load_file(ConfigPath).each_pair{|k,v| {k=>v.to_s.strip}}.symbolize_keys! + @config ||= YAML.load_file(path).each_pair{|k,v| {k=>v.to_s.strip}}.symbolize_keys! end # Get the preferred access level for iPaper documents def access_level config[:access] || 'private' @@ -118,17 +119,18 @@ end module ClassMethods # Load and inject ScribdFu goodies - def has_ipaper_and_uses(str) + # opts can be :on => :create, defaults to :on => :save + def has_ipaper_and_uses(str, opts = {:on => :save }) check_environment load_base_plugin(str) include InstanceMethods - after_save :upload_to_scribd # This *MUST* be an after_save + send("after_#{opts[:on]}", :upload_to_scribd) # This *MUST* be an after_save before_destroy :destroy_ipaper_document end private @@ -263,5 +265,6 @@ end # Let's do this. ActiveRecord::Base.send(:include, ScribdFu) if Object.const_defined?("ActiveRecord") +