Module: Card::Set::Self::Admin

Extended by:
Card::Set
Defined in:
card/tmpsets/set/mod001-admin/self/admin.rb,
card/tmpsets/set/mod014-card-mod-carrierwave/self/admin.rb,
card/tmpsets/set/mod013-card-mod-carrierwave/self/admin.rb

Overview

Set: The card “Admin”

Defined Under Namespace

Modules: HtmlFormat

Constant Summary

Constants included from Helpers

Helpers::SET_PATTERN_TEST_REGEXP

Constants included from Event::Api

Event::Api::OPTIONS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Card::Set

reset_modules

Methods included from I18nScope

#mod_name, #scope

Methods included from Loader

#clean_empty_module_from_hash, #clean_empty_modules, #extended, #process_base_modules, #register_set

Methods included from Helpers

#method_missing, #num_set_parts, #pattern_code, #respond_to_missing?, #set_name_parts, #shortname, #underscore

Methods included from AdvancedApi

#attachment, #define_set_from_error, #ensure_set, #setting_opts, #stage_method

Methods included from Format

#before, #format, layout_method_name, #view, view_method_name, view_setting_method_name, wrapper_method_name

Methods included from Inheritance

#include_set, #include_set_formats

Methods included from Basket

#abstract_basket, #add_to_basket, #basket, #unshift_basket

Methods included from Trait

#card_accessor, #card_reader, #card_writer, #require_field

Methods included from Event::Api

#event

Class Method Details

.source_locationObject



8
# File 'card/tmpsets/set/mod001-admin/self/admin.rb', line 8

def self.source_location; "/Users/ethan/dev/decko/gem/card/mod/admin/set/self/admin.rb"; end

Instance Method Details

#current_memory_usageObject



138
139
140
# File 'card/tmpsets/set/mod001-admin/self/admin.rb', line 138

def current_memory_usage
  `ps -o rss= -p #{Process.pid}`.to_i
end

#event: admin_tasksObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'card/tmpsets/set/mod001-admin/self/admin.rb', line 22

event :admin_tasks, :initialize, on: :update do
  return unless (task = Env.params[:task])
  raise Card::Error::PermissionDenied, self unless Auth.always_ok?
  case task.to_sym
  when :clear_cache          then Card::Cache.reset_all
  when :repair_references    then Card::Reference.repair_all
  when :repair_permissions   then Card.repair_all_permissions
  when :clear_solid_cache    then Card.clear_solid_cache
  when :clear_machine_cache  then Card.reset_all_machines
  when :clear_script_cache   then Card.reset_script_machine
  when :clear_history
    not_allowed "clear history" unless irreversibles_tasks_allowed?
    Card::Action.delete_old
  else
    run_task_from_task_basket task
  end
  abort :success
end

#irreversibles_tasks_allowed?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'card/tmpsets/set/mod001-admin/self/admin.rb', line 47

def irreversibles_tasks_allowed?
  Cardio.config.allow_irreversible_admin_tasks
end

#not_allowed(task) ⇒ Object



41
42
43
44
45
# File 'card/tmpsets/set/mod001-admin/self/admin.rb', line 41

def not_allowed task
  raise Card::Error::PermissionDenied,
        "The admin task '#{task}' is disabled for security reasons.<br>"\
        "You can enable it with the config option 'allow_irreversible_admin_tasks'"
end

#profile_memory(&block) ⇒ Object



142
143
144
145
146
147
148
149
150
# File 'card/tmpsets/set/mod001-admin/self/admin.rb', line 142

def profile_memory &block
  before = current_memory_usage
  if block_given?
    instance_eval(&block)
  else
    before = 0
  end
  (current_memory_usage - before) / 1024.to_i
end

#run_task_from_task_basket(task) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'card/tmpsets/set/mod001-admin/self/admin.rb', line 12

def run_task_from_task_basket task
  task = task.to_sym
  task_data = tasks.find {|h| h[:name].to_sym == task.to_sym}
  if !irreversibles_tasks_allowed? && task_data[:irreversible]
    not_allowed task_data[:stats][:link_text]
  else
    task_data[:execute_policy].call if task_data
  end
end