Module: FinePrint::ActionController::Base

Defined in:
lib/fine_print/action_controller/base.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
# File 'lib/fine_print/action_controller/base.rb', line 5

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#fine_print_redirect(user, *contracts) ⇒ Object

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



42
43
44
45
46
47
48
49
50
51
52
53
# 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) ⇒ Object

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



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# 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_returnObject

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



58
59
60
# File 'lib/fine_print/action_controller/base.rb', line 58

def fine_print_return
  redirect_back key: :fine_print_return_to
end