Module: Draftsman
- Defined in:
- lib/draftsman.rb,
lib/draftsman/model.rb,
lib/draftsman/config.rb,
lib/draftsman/version.rb,
lib/draftsman/frameworks/rails.rb,
lib/draftsman/serializers/json.rb,
lib/draftsman/serializers/yaml.rb,
lib/draftsman/frameworks/sinatra.rb,
lib/draftsman/attributes_serialization.rb,
lib/generators/draftsman/install_generator.rb
Overview
Draftsman’s module methods can be called in both models and controllers.
Defined Under Namespace
Modules: AttributesSerialization, Model, Rails, Serializers, Sinatra Classes: Config, Draft, InstallGenerator
Constant Summary collapse
- VERSION =
'0.7.0'
Class Method Summary collapse
-
.active_record_belongs_to_required? ⇒ Boolean
Returns whether or not ActiveRecord is configured to assume that ‘belongs_to` associations are required.
-
.active_record_protected_attributes? ⇒ Boolean
Returns whether or not ActiveRecord is configured to require mass assignment whitelisting via ‘attr_accessible`.
-
.controller_info ⇒ Object
Returns any information from the controller that you want Draftsman to store.
-
.controller_info=(value) ⇒ Object
Sets any information from the controller that you want Draftsman to store.
-
.draft_class_name ⇒ Object
Returns default class name used for drafts.
-
.draft_class_name=(class_name) ⇒ Object
Sets default class name to use for drafts.
-
.enabled=(value) ⇒ Object
Switches Draftsman on or off.
-
.enabled? ⇒ Boolean
Returns ‘true` if Draftsman is on, `false` otherwise.
-
.enabled_for_controller=(value) ⇒ Object
Sets whether Draftsman is enabled or disabled for the current request.
-
.enabled_for_controller? ⇒ Boolean
Returns ‘true` if Draftsman is enabled for the request, `false` otherwise.
-
.serializer ⇒ Object
Returns serializer to use for ‘object`, `object_changes`, and `previous_draft` columns.
-
.serializer=(value) ⇒ Object
Sets serializer to use for ‘object`, `object_changes`, and `previous_draft` columns.
-
.stash_drafted_changes=(value) ⇒ Object
Sets whether or not ‘#save_draft` should stash drafted changes into the associated draft record or persist them to the main item.
-
.stash_drafted_changes? ⇒ Boolean
Returns setting for whether or not ‘#save_draft` should stash drafted changes into the associated draft record.
-
.timestamp_field ⇒ Object
Returns the field which records when a draft was created.
-
.timestamp_field=(field_name) ⇒ Object
Set the field which records when a draft was created.
-
.whodunnit ⇒ Object
Returns who is reponsible for any changes that occur.
-
.whodunnit=(value) ⇒ Object
Sets who is responsible for any changes that occur.
-
.whodunnit_field ⇒ Object
Returns the field which records whodunnit data.
-
.whodunnit_field=(field_name) ⇒ Object
Sets global attribute name for ‘whodunnit` data.
Class Method Details
.active_record_belongs_to_required? ⇒ Boolean
Returns whether or not ActiveRecord is configured to assume that ‘belongs_to` associations are required.
34 35 36 |
# 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? ⇒ Boolean
Returns whether or not ActiveRecord is configured to require mass assignment whitelisting via ‘attr_accessible`.
39 40 41 |
# 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 ⇒ Object
Returns any information from the controller that you want Draftsman to store.
See ‘Draftsman::Controller#info_for_draftsman`.
46 47 48 |
# File 'lib/draftsman.rb', line 46 def self.controller_info draftsman_store[:controller_info] end |
.controller_info=(value) ⇒ Object
Sets any information from the controller that you want Draftsman to store. By default, this is set automatically by a before filter.
52 53 54 |
# File 'lib/draftsman.rb', line 52 def self.controller_info=(value) draftsman_store[:controller_info] = value end |
.draft_class_name ⇒ Object
Returns default class name used for drafts.
57 58 59 |
# File 'lib/draftsman.rb', line 57 def self.draft_class_name draftsman_store[:draft_class_name] end |
.draft_class_name=(class_name) ⇒ Object
Sets default class name to use for drafts.
62 63 64 |
# File 'lib/draftsman.rb', line 62 def self.draft_class_name=(class_name) draftsman_store[:draft_class_name] = class_name end |
.enabled=(value) ⇒ Object
Switches Draftsman on or off.
11 12 13 |
# File 'lib/draftsman.rb', line 11 def self.enabled=(value) Draftsman.config.enabled = value end |
.enabled? ⇒ Boolean
Returns ‘true` if Draftsman is on, `false` otherwise. Draftsman is enabled by default.
17 18 19 |
# File 'lib/draftsman.rb', line 17 def self.enabled? !!Draftsman.config.enabled end |
.enabled_for_controller=(value) ⇒ Object
Sets whether Draftsman is enabled or disabled for the current request.
22 23 24 |
# File 'lib/draftsman.rb', line 22 def self.enabled_for_controller=(value) draftsman_store[:request_enabled_for_controller] = value end |
.enabled_for_controller? ⇒ Boolean
Returns ‘true` if Draftsman is enabled for the request, `false` otherwise.
See ‘Draftsman::Rails::Controller#draftsman_enabled_for_controller`.
29 30 31 |
# File 'lib/draftsman.rb', line 29 def self.enabled_for_controller? !!draftsman_store[:request_enabled_for_controller] end |
.serializer ⇒ Object
Returns serializer to use for ‘object`, `object_changes`, and `previous_draft` columns.
77 78 79 |
# File 'lib/draftsman.rb', line 77 def self.serializer Draftsman.config.serializer end |
.serializer=(value) ⇒ Object
Sets serializer to use for ‘object`, `object_changes`, and `previous_draft` columns.
82 83 84 |
# File 'lib/draftsman.rb', line 82 def self.serializer=(value) Draftsman.config.serializer = value end |
.stash_drafted_changes=(value) ⇒ Object
Sets whether or not ‘#save_draft` should stash drafted changes into the associated draft record or persist them to the main item.
88 89 90 |
# File 'lib/draftsman.rb', line 88 def self.stash_drafted_changes=(value) Draftsman.config.stash_drafted_changes = value end |
.stash_drafted_changes? ⇒ Boolean
Returns setting for whether or not ‘#save_draft` should stash drafted changes into the associated draft record.
94 95 96 |
# File 'lib/draftsman.rb', line 94 def self.stash_drafted_changes? Draftsman.config.stash_drafted_changes? end |
.timestamp_field ⇒ Object
Returns the field which records when a draft was created.
72 73 74 |
# File 'lib/draftsman.rb', line 72 def self. Draftsman.config. end |
.timestamp_field=(field_name) ⇒ Object
Set the field which records when a draft was created.
67 68 69 |
# File 'lib/draftsman.rb', line 67 def self.(field_name) Draftsman.config. = field_name end |
.whodunnit ⇒ Object
Returns who is reponsible for any changes that occur.
99 100 101 |
# File 'lib/draftsman.rb', line 99 def self.whodunnit draftsman_store[:whodunnit] end |
.whodunnit=(value) ⇒ Object
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`.
106 107 108 |
# File 'lib/draftsman.rb', line 106 def self.whodunnit=(value) draftsman_store[:whodunnit] = value end |
.whodunnit_field ⇒ Object
Returns the field which records whodunnit data.
111 112 113 |
# File 'lib/draftsman.rb', line 111 def self.whodunnit_field Draftsman.config.whodunnit_field end |
.whodunnit_field=(field_name) ⇒ Object
Sets global attribute name for ‘whodunnit` data.
116 117 118 |
# File 'lib/draftsman.rb', line 116 def self.whodunnit_field=(field_name) Draftsman.config.whodunnit_field = field_name end |