module FinePrint::ActionController::Base

Public Class Methods

included(base) click to toggle source
# File lib/fine_print/action_controller/base.rb, line 5
def self.included(base)
  base.extend(ClassMethods)
end

Public Instance Methods

fine_print_redirect(user, *contracts) click to toggle source

Accepts a user, an array of contract ids to be signed and an options hash Calls the ‘redirect_to_contracts_proc` with the given parameters

# File lib/fine_print/action_controller/base.rb, line 42
def fine_print_redirect(user, *contracts)
  options = contracts.last.is_a?(Hash) ? contracts.pop : {}
  contracts = contracts.flatten

  blk = options[:redirect_to_contracts_proc] || \
        FinePrint.config.redirect_to_contracts_proc

  # Use action_interceptor to save the current url
  store_url key: :fine_print_return_to

  instance_exec user, contracts, &blk
end
fine_print_require(*names) click to toggle source

Accepts an array of contract names and an options hash Checks if the current user has signed the given contracts and calls fine_print_redirect if not Options relevant to FinePrint are passed to fine_print_redirect If no names are given, requires all contracts

# File lib/fine_print/action_controller/base.rb, line 14
def fine_print_require(*names)
  options = names.last.is_a?(Hash) ? names.pop : {}
  fp_opts = options.slice(*FinePrint::Configuration::CONTROLLER_OPTIONS)

  # Convert names to an array of Strings
  contract_names = names.flatten.map(&:to_s)
  contract_names = ['all'] if contract_names.empty?
  contract_names = FinePrint::Contract.all.to_a.map(&:name).uniq \
    if contract_names.include?('all')

  user = instance_exec &FinePrint.config.current_user_proc

  can_sign = instance_exec(user, &FinePrint.config.authenticate_user_proc)

  return if !can_sign || performed?

  unsigned_contracts = FinePrint.unsigned_contracts_for(
    user, name: contract_names
  )

  # Return quietly if all contracts signed
  return if unsigned_contracts.blank?

  fine_print_redirect(user, unsigned_contracts, fp_opts)
end
fine_print_return() click to toggle source

Accepts no arguments Redirects the user back to the url they were at before ‘fine_print_redirect` redirected them

# File lib/fine_print/action_controller/base.rb, line 58
def fine_print_return
  redirect_back key: :fine_print_return_to
end

Protected Instance Methods

fine_print_skipped_contract_names() click to toggle source
# File lib/fine_print/action_controller/base.rb, line 64
def fine_print_skipped_contract_names
  @fine_print_skipped_contract_names ||= []
end