Module: Papermill::ClassMethods

Defined in:
lib/papermill/papermill.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#papermill_associationsObject (readonly)

Returns the value of attribute papermill_associations.



23
24
25
# File 'lib/papermill/papermill.rb', line 23

def papermill_associations
  @papermill_associations
end

Instance Method Details

#inherited(subclass) ⇒ Object



51
52
53
54
# File 'lib/papermill/papermill.rb', line 51

def inherited(subclass)
  subclass.instance_variable_set("@papermill_associations", @papermill_associations)
  super
end

#papermill(*args) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/papermill/papermill.rb', line 25

def papermill(*args)
  assoc_name = (!args.first.is_a?(Hash) && args.shift || Papermill::options[:base_association_name]).to_sym
  local_options = args.first || {}

  (@papermill_associations ||= {}).merge!( assoc_name => Papermill::options.deep_merge(local_options) )
  
  include Papermill::InstanceMethods
  after_create :rebase_assets
  has_many :papermill_assets, :as => "assetable", :dependent => :destroy

  [assoc_name, Papermill::options[:base_association_name].to_sym].uniq.each do |assoc|
    define_method assoc do |*options|
      scope = PapermillAsset.scoped(:conditions => {:assetable_id => self.id, :assetable_type => self.class.base_class.name})
      if assoc != Papermill::options[:base_association_name]
        scope = scope.scoped(:conditions => { :assetable_key => assoc.to_s })
      elsif options.first && !options.first.is_a?(Hash)
        scope = scope.scoped(:conditions => { :assetable_key => options.shift.to_s.nie })
      end
      scope = scope.scoped(options.shift) if options.first
      scope
    end
  end
  ActionController::Dispatcher.middleware.delete(FlashSessionCookieMiddleware) rescue true
  ActionController::Dispatcher.middleware.insert_before(ActionController::Base.session_store, FlashSessionCookieMiddleware, ActionController::Base.session_options[:key]) rescue true
end