Skip to content

Commit

Permalink
Closes #53 Add option to not stash drafted data separately
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Peters committed Nov 16, 2016
1 parent 43c95ec commit 39e74ef
Show file tree
Hide file tree
Showing 8 changed files with 1,770 additions and 708 deletions.
26 changes: 19 additions & 7 deletions lib/draftsman.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,30 @@ 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.
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.
def self.stash_drafted_changes?
Draftsman.config.stash_drafted_changes?
end

# Returns who is reponsible for any changes that occur.
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`.
def self.whodunnit=(value)
draftsman_store[:whodunnit] = value
end

# Returns the field which records whodunnit data.
def self.whodunnit_field
Draftsman.config.whodunnit_field
Expand All @@ -93,13 +112,6 @@ def self.whodunnit_field=(field_name)
Draftsman.config.whodunnit_field = field_name
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`.
def self.whodunnit=(value)
draftsman_store[:whodunnit] = value
end

private

# Thread-safe hash to hold Draftman's data. Initializing with needed default values.
Expand Down
4 changes: 3 additions & 1 deletion lib/draftsman/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
module Draftsman
class Config
include Singleton
attr_accessor :serializer, :timestamp_field, :whodunnit_field
attr_accessor :serializer, :timestamp_field, :whodunnit_field, :stash_drafted_changes
alias :stash_drafted_changes? :stash_drafted_changes

def initialize
@timestamp_field = :created_at
@mutex = Mutex.new
@serializer = Draftsman::Serializers::Yaml
@enabled = true
@whodunnit_field = :whodunnit
@stash_drafted_changes = true
end

# Indicates whether Draftsman is on or off. Default: true.
Expand Down
Loading

0 comments on commit 39e74ef

Please sign in to comment.