module Redcrumbs::Creation

Public Instance Methods

create_crumb() click to toggle source
# File lib/redcrumbs/creation.rb, line 47
def create_crumb
  n = Redcrumbs.crumb_class.build_with_modifications(self)
  n.save
  n
end
crumbs() click to toggle source
# File lib/redcrumbs/creation.rb, line 5
def crumbs
  Redcrumbs.crumb_class.all(
    :subject_type => self.class.to_s, 
    :subject_id => self.id
  )
end
notify_changes() click to toggle source

This is called after the record is saved to store the changes on the model, including anything done in before_save validations

# File lib/redcrumbs/creation.rb, line 54
def notify_changes
  create_crumb unless watched_changes.empty?
end
serialized_as_redcrumbs_subject() click to toggle source
# File lib/redcrumbs/creation.rb, line 43
def serialized_as_redcrumbs_subject
  storeable_attributes.merge(storable_methods)
end
storable_attributes_keys() click to toggle source
# File lib/redcrumbs/creation.rb, line 16
def storable_attributes_keys
  store = self.class.redcrumbs_options[:store]
  
  store[:only] or 
  symbolized_attribute_keys(store[:except]) or
  []
end
storable_methods() click to toggle source

Todo: Fix inconsistent naming; storable vs storeable

# File lib/redcrumbs/creation.rb, line 39
def storable_methods
  storable_methods_names.inject({}) {|h, n| h.merge(n.to_s => send(n))}
end
storable_methods_names() click to toggle source
# File lib/redcrumbs/creation.rb, line 28
def storable_methods_names
  store = self.class.redcrumbs_options[:store]

  if store[:methods]
    methods.select {|method| store[:methods].include?(method.to_sym)}
  else
    []
  end
end
storeable_attributes() click to toggle source
# File lib/redcrumbs/creation.rb, line 24
def storeable_attributes
  attributes.slice *storable_attributes_keys.map(&:to_s)
end
watched_changes() click to toggle source
# File lib/redcrumbs/creation.rb, line 12
def watched_changes
  changes.slice(*self.class.redcrumbs_options[:only])
end

Private Instance Methods

methods_from_array(array) click to toggle source
# File lib/redcrumbs/creation.rb, line 67
def methods_from_array(array)
  self.class.instance_methods.select {|method| array.include?(method.to_sym)}
end
symbolized_attribute_keys(except = []) click to toggle source
# File lib/redcrumbs/creation.rb, line 60
def symbolized_attribute_keys(except = [])
  return nil unless except

  symbolized_attribute_keys = attributes.dup.symbolize_keys!.keys
  symbolized_attribute_keys.reject {|key| except.include?(key)}
end