module Draftsman

Draftsman's module methods can be called in both models and controllers.

Constants

VERSION

Public Class Methods

active_record_belongs_to_required?() click to toggle source

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
active_record_protected_attributes?() click to toggle source

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
controller_info() click to toggle source

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
controller_info=(value) click to toggle source

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
draft_class_name() click to toggle source

Returns default class name used for drafts.

# File lib/draftsman.rb, line 57
def self.draft_class_name
  draftsman_store[:draft_class_name]
end
draft_class_name=(class_name) click to toggle source

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
enabled=(value) click to toggle source

Switches Draftsman on or off.

# File lib/draftsman.rb, line 11
def self.enabled=(value)
  Draftsman.config.enabled = value
end
enabled?() click to toggle source

Returns `true` if Draftsman is on, `false` otherwise. Draftsman is enabled by default.

# File lib/draftsman.rb, line 17
def self.enabled?
  !!Draftsman.config.enabled
end
enabled_for_controller=(value) click to toggle source

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
enabled_for_controller?() click to toggle source

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
serializer() click to toggle source

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
serializer=(value) click to toggle source

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
stash_drafted_changes=(value) click to toggle source

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
stash_drafted_changes?() click to toggle source

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
timestamp_field() click to toggle source

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
timestamp_field=(field_name) click to toggle source

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
whodunnit() click to toggle source

Returns who is reponsible for any changes that occur.

# File lib/draftsman.rb, line 99
def self.whodunnit
  draftsman_store[:whodunnit]
end
whodunnit=(value) click to toggle source

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
whodunnit_field() click to toggle source

Returns the field which records whodunnit data.

# File lib/draftsman.rb, line 111
def self.whodunnit_field
  Draftsman.config.whodunnit_field
end
whodunnit_field=(field_name) click to toggle source

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

config() click to toggle source

Returns Draftman's configuration object.

# File lib/draftsman.rb, line 128
def self.config
  @@config ||= Draftsman::Config.instance
end
configure() { |config| ... } click to toggle source
# File lib/draftsman.rb, line 132
def self.configure
  yield config
end
draftsman_store() click to toggle source

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