Class: Sapling::Util

Inherits:
Object
  • Object
show all
Defined in:
lib/sapling/util.rb

Constant Summary collapse

CONTEXT_ID_ONLY_ENABLED_IF_100_PERCENT_ENABLED =
99

Class Method Summary collapse

Class Method Details

.context_id(options) ⇒ Object



6
7
8
# File 'lib/sapling/util.rb', line 6

def context_id(options)
  options[:context_id] || ((u=options[:user]) && u.id)
end

.modded_context_id(options) ⇒ Object



9
10
11
# File 'lib/sapling/util.rb', line 9

def modded_context_id(options)
  ((cid=context_id(options)) && (cid%100)) || CONTEXT_ID_ONLY_ENABLED_IF_100_PERCENT_ENABLED
end

.normalized_options(options, controller = nil) ⇒ Object



13
14
15
16
17
18
# File 'lib/sapling/util.rb', line 13

def normalized_options(options,controller=nil)
  options[:user] ||= controller.current_user if controller
  options[:user_id] ||= options[:user].id if options[:user]
  options[:context_id] ||= options[:user_id]
  options
end