Class: PaperTrail::Human::Configuration
- Inherits:
-
Object
- Object
- PaperTrail::Human::Configuration
- Defined in:
- lib/paper_trail/human/configuration.rb
Constant Summary collapse
- DEFAULT_IGNORED_FIELDS =
%w[id created_at updated_at].freeze
Instance Attribute Summary collapse
-
#after_format ⇒ Object
Returns the value of attribute after_format.
-
#extend_version_model ⇒ Object
Returns the value of attribute extend_version_model.
-
#field_name_resolver ⇒ Object
Returns the value of attribute field_name_resolver.
-
#ignored_fields ⇒ Object
Returns the value of attribute ignored_fields.
-
#translate_events ⇒ Object
Returns the value of attribute translate_events.
-
#whodunnit_resolver ⇒ Object
Returns the value of attribute whodunnit_resolver.
Instance Method Summary collapse
- #config_for(model_name) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #register(model_name) {|model_config| ... } ⇒ Object
- #resolve_item_name(version) ⇒ Object
- #resolve_whodunnit(id) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/paper_trail/human/configuration.rb', line 12 def initialize @model_configs = {} @ignored_fields = DEFAULT_IGNORED_FIELDS.dup @whodunnit_resolver = nil @field_name_resolver = nil @translate_events = false @extend_version_model = false @after_format = nil @mutex = Mutex.new end |
Instance Attribute Details
#after_format ⇒ Object
Returns the value of attribute after_format.
8 9 10 |
# File 'lib/paper_trail/human/configuration.rb', line 8 def after_format @after_format end |
#extend_version_model ⇒ Object
Returns the value of attribute extend_version_model.
8 9 10 |
# File 'lib/paper_trail/human/configuration.rb', line 8 def extend_version_model @extend_version_model end |
#field_name_resolver ⇒ Object
Returns the value of attribute field_name_resolver.
8 9 10 |
# File 'lib/paper_trail/human/configuration.rb', line 8 def field_name_resolver @field_name_resolver end |
#ignored_fields ⇒ Object
Returns the value of attribute ignored_fields.
10 11 12 |
# File 'lib/paper_trail/human/configuration.rb', line 10 def ignored_fields @ignored_fields end |
#translate_events ⇒ Object
Returns the value of attribute translate_events.
8 9 10 |
# File 'lib/paper_trail/human/configuration.rb', line 8 def translate_events @translate_events end |
#whodunnit_resolver ⇒ Object
Returns the value of attribute whodunnit_resolver.
8 9 10 |
# File 'lib/paper_trail/human/configuration.rb', line 8 def whodunnit_resolver @whodunnit_resolver end |
Instance Method Details
#config_for(model_name) ⇒ Object
33 34 35 |
# File 'lib/paper_trail/human/configuration.rb', line 33 def config_for(model_name) @model_configs[model_name.to_s] end |
#register(model_name) {|model_config| ... } ⇒ Object
27 28 29 30 31 |
# File 'lib/paper_trail/human/configuration.rb', line 27 def register(model_name, &) model_config = ModelConfig.new yield(model_config) @mutex.synchronize { @model_configs[model_name.to_s] = model_config.freeze } end |
#resolve_item_name(version) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/paper_trail/human/configuration.rb', line 43 def resolve_item_name(version) model_config = config_for(version.item_type) return nil unless model_config&.item_name_attribute attr = model_config.item_name_attribute return attr.call(version) if attr.respond_to?(:call) item = find_item(version) item&.public_send(attr) rescue NoMethodError, ActiveRecord::RecordNotFound nil end |
#resolve_whodunnit(id) ⇒ Object
37 38 39 40 41 |
# File 'lib/paper_trail/human/configuration.rb', line 37 def resolve_whodunnit(id) return id unless whodunnit_resolver whodunnit_resolver.call(id) end |