module Draftsman
Draftsman's module methods can be called in both models and controllers.
Constants
- VERSION
Public Class Methods
Returns whether or not ActiveRecord is configured to assume that `belongs_to` associations are required.
# File lib/draftsman.rb, line 34 def self.active_record_belongs_to_required? @active_record_belongs_to_required ||= ActiveRecord::VERSION::STRING.to_f >= 5.0 end
Returns whether or not ActiveRecord is configured to require mass assignment whitelisting via `attr_accessible`.
# File lib/draftsman.rb, line 39 def self.active_record_protected_attributes? @active_record_protected_attributes ||= ActiveRecord::VERSION::STRING.to_f < 4.0 || defined?(ProtectedAttributes) end
Returns any information from the controller that you want Draftsman
to store.
See `Draftsman::Controller#info_for_draftsman`.
# File lib/draftsman.rb, line 46 def self.controller_info draftsman_store[:controller_info] end
Sets any information from the controller that you want Draftsman
to store. By default, this is set automatically by a before filter.
# File lib/draftsman.rb, line 52 def self.controller_info=(value) draftsman_store[:controller_info] = value end
Returns default class name used for drafts.
# File lib/draftsman.rb, line 57 def self.draft_class_name draftsman_store[:draft_class_name] end
Sets default class name to use for drafts.
# File lib/draftsman.rb, line 62 def self.draft_class_name=(class_name) draftsman_store[:draft_class_name] = class_name end
Switches Draftsman
on or off.
# File lib/draftsman.rb, line 11 def self.enabled=(value) Draftsman.config.enabled = value end
Sets whether Draftsman
is enabled or disabled for the current request.
# File lib/draftsman.rb, line 22 def self.enabled_for_controller=(value) draftsman_store[:request_enabled_for_controller] = value end
Returns `true` if Draftsman
is enabled for the request, `false` otherwise.
See `Draftsman::Rails::Controller#draftsman_enabled_for_controller`.
# File lib/draftsman.rb, line 29 def self.enabled_for_controller? !!draftsman_store[:request_enabled_for_controller] end
Returns serializer to use for `object`, `object_changes`, and `previous_draft` columns.
# File lib/draftsman.rb, line 77 def self.serializer Draftsman.config.serializer end
Sets serializer to use for `object`, `object_changes`, and `previous_draft` columns.
# File lib/draftsman.rb, line 82 def self.serializer=(value) Draftsman.config.serializer = value end
Sets whether or not `#save_draft` should stash drafted changes into the associated draft record or persist them to the main item.
# File lib/draftsman.rb, line 88 def self.stash_drafted_changes=(value) Draftsman.config.stash_drafted_changes = value end
Returns setting for whether or not `#save_draft` should stash drafted changes into the associated draft record.
# File lib/draftsman.rb, line 94 def self.stash_drafted_changes? Draftsman.config.stash_drafted_changes? end
Returns the field which records when a draft was created.
# File lib/draftsman.rb, line 72 def self.timestamp_field Draftsman.config.timestamp_field end
Set the field which records when a draft was created.
# File lib/draftsman.rb, line 67 def self.timestamp_field=(field_name) Draftsman.config.timestamp_field = field_name end
Returns who is reponsible for any changes that occur.
# File lib/draftsman.rb, line 99 def self.whodunnit draftsman_store[:whodunnit] end
Sets who is responsible for any changes that occur. You would normally use this in a migration or on the console when working with models directly. In a controller, it is set automatically to the `current_user`.
# File lib/draftsman.rb, line 106 def self.whodunnit=(value) draftsman_store[:whodunnit] = value end
Returns the field which records whodunnit data.
# File lib/draftsman.rb, line 111 def self.whodunnit_field Draftsman.config.whodunnit_field end
Sets global attribute name for `whodunnit` data.
# File lib/draftsman.rb, line 116 def self.whodunnit_field=(field_name) Draftsman.config.whodunnit_field = field_name end
Private Class Methods
Returns Draftman's configuration object.
# File lib/draftsman.rb, line 128 def self.config @@config ||= Draftsman::Config.instance end
# File lib/draftsman.rb, line 132 def self.configure yield config end
Thread-safe hash to hold Draftman's data. Initializing with needed default values.
# File lib/draftsman.rb, line 123 def self.draftsman_store Thread.current[:draft] ||= { draft_class_name: 'Draftsman::Draft' } end