Skip to content

Commit

Permalink
debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
bbenezech committed Mar 16, 2010
1 parent 67d62b8 commit d334c7b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 41 deletions.
64 changes: 31 additions & 33 deletions lib/papermill/papermill.rb
@@ -1,33 +1,44 @@
module Papermill
MSWIN = (Config::CONFIG['host_os'] =~ /mswin|mingw/)

def self.included(base)
base.extend(ClassMethods)
base.include(InstanceMethods)
base.send :alias_method_chain, :method_missing, :papermill
base.send :alias_method_chain, :respond_to?, :papermill
ActionController::Dispatcher.middleware.insert_before(ActionController::Base.session_store, FlashSessionCookieMiddleware, ActionController::Base.session_options[:key]) unless ActionController::Dispatcher.middleware.include?(FlashSessionCookieMiddleware)
def self.options
@options ||= BASE_OPTIONS.deep_merge(defined?(OPTIONS) ? OPTIONS : {})
end

module InstanceMethods
def papermill(key, through = (self.class.papermill_options && (self.class.papermill_options[key.to_sym] || self.class.papermill_options[:default]) || Papermill::options)[:through])
PapermillAsset.papermill(self.class.base_class.name, self.id, key.to_s, through)
end
def self.compute_paperclip_path
path = []
path << (options[:use_id_partition] ? ":id_partition" : ":id")
path << (":url_key" if options[:use_url_key])
path << ":style"
path << ":basename.:extension"
path.compact.join("/")
end

def self.included(base)
base.extend(ClassMethods)
base.class_eval do
def papermill(key, through = ((po = self.class.papermill_options) ? po[key.to_sym] || po[:default] : Papermill::options)[:through])
PapermillAsset.papermill(self.class.base_class.name, self.id, key.to_s, through)
end

def respond_to_with_papermill?(method, *args, &block)
respond_to_without_papermill?(method, *args, &block) || method.to_s =~ /^papermill_[^_]+_ids=$/
end
def respond_to_with_papermill?(method, *args, &block)
respond_to_without_papermill?(method, *args, &block) || method.to_s =~ /^papermill_[^_]+_ids=$/
end

def method_missing_with_papermill(method, *args, &block)
if method.to_s =~ /^papermill_[^_]+_ids=$/
self.class.papermill(method.to_s[10..-6])
self.send(method, *args, &block)
else
method_missing_without_papermill(method, *args, &block)
def method_missing_with_papermill(method, *args, &block)
if method.to_s =~ /^papermill_[^_]+_ids=$/
self.class.papermill(method.to_s[10..-6])
self.send(method, *args, &block)
else
method_missing_without_papermill(method, *args, &block)
end
end
end
base.send :alias_method_chain, :method_missing, :papermill
base.send :alias_method_chain, :respond_to?, :papermill
ActionController::Dispatcher.middleware.insert_before(ActionController::Base.session_store, FlashSessionCookieMiddleware, ActionController::Base.session_options[:key]) unless ActionController::Dispatcher.middleware.include?(FlashSessionCookieMiddleware)
end

module ClassMethods
attr_reader :papermill_options

Expand Down Expand Up @@ -66,19 +77,6 @@ def papermill_#{assoc_key}_ids=(ids)
end
}
end

def options
@options ||= BASE_OPTIONS.deep_merge(defined?(OPTIONS) ? OPTIONS : {})
end

def compute_paperclip_path
path = []
path << (options[:use_id_partition] ? ":id_partition" : ":id")
path << (":url_key" if options[:use_url_key])
path << ":style"
path << ":basename.:extension"
path.compact.join("/")
end
end
end
end
12 changes: 4 additions & 8 deletions lib/papermill/papermill_asset.rb
Expand Up @@ -15,21 +15,17 @@ class PapermillAsset < ActiveRecord::Base

named_scope :papermill, lambda { |assetable_type, assetable_id, assetable_key, through|
through ?
{ :joins => ["INNER JOIN papermill_associations ON papermill_assets.id = papermill_associations.papermill_asset_id \
AND papermill_associations.assetable_type = ? \
AND papermill_associations.assetable_id = ? \
AND papermill_associations.assetable_key = ?",
assetable_type, assetable_id, assetable_key],
{ :joins => "INNER JOIN papermill_associations ON papermill_assets.id = papermill_associations.papermill_asset_id \
AND papermill_associations.assetable_type = #{connection.quote assetable_type} \
AND papermill_associations.assetable_id = #{assetable_id.to_i} \
AND papermill_associations.assetable_key = #{connection.quote assetable_key}",
:order => "papermill_associations.position" } :
{ :conditions => {
:assetable_type => assetable_type,
:assetable_id => assetable_id,
:assetable_key => assetable_key.to_s },
:order => "papermill_assets.position" }
}

named_scope :papermill_through, lambda { |assetable_type, assetable_id, assetable_key| {
} }

def assetable_type=(sType)
super(sType.to_s.classify.constantize.base_class.to_s)
Expand Down

0 comments on commit d334c7b

Please sign in to comment.