Class: Anony::ModelConfig
- Inherits:
-
Object
- Object
- Anony::ModelConfig
- Defined in:
- lib/anony/model_config.rb
Defined Under Namespace
Classes: UndefinedStrategy
Instance Method Summary collapse
-
#apply(instance) ⇒ Object
private
Applies the given strategy, taking into account any filters or conditions.
-
#destroy ⇒ Object
Use the deletion strategy instead of anonymising individual fields.
-
#initialize(model_class) {|block| ... } ⇒ ModelConfig
constructor
private
Constructs a new instance of ModelConfig.
-
#overwrite(&block) ⇒ Object
Use the overwrite strategy to configure rules for individual fields.
-
#skip_if(&if_condition) ⇒ Object
Prevent any anonymisation strategy being applied when the provided block evaluates to true.
Constructor Details
#initialize(model_class) {|block| ... } ⇒ ModelConfig
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Constructs a new instance of ModelConfig.
29 30 31 32 33 34 |
# File 'lib/anony/model_config.rb', line 29 def initialize(model_class, &block) @model_class = model_class @strategy = UndefinedStrategy.new @skip_filter = nil instance_exec(&block) if block_given? end |
Instance Method Details
#apply(instance) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Applies the given strategy, taking into account any filters or conditions.
41 42 43 44 45 |
# File 'lib/anony/model_config.rb', line 41 def apply(instance) return Result.skipped if @skip_filter && instance.instance_exec(&@skip_filter) @strategy.apply(instance) end |
#destroy ⇒ Object
Use the deletion strategy instead of anonymising individual fields. This method is incompatible with the fields strategy.
This method takes no arguments or blocks.
58 59 60 61 62 63 64 65 |
# File 'lib/anony/model_config.rb', line 58 def destroy raise ArgumentError, ":destroy takes no block" if block_given? unless @strategy.is_a?(UndefinedStrategy) raise ArgumentError, "Cannot specify :destroy when another strategy already defined" end @strategy = Strategies::Destroy.new end |
#overwrite(&block) ⇒ Object
Use the overwrite strategy to configure rules for individual fields. This method is incompatible with the destroy strategy.
This method takes a configuration block. All configuration is applied to Anony::Strategies::Overwrite.
81 82 83 84 85 86 87 |
# File 'lib/anony/model_config.rb', line 81 def overwrite(&block) unless @strategy.is_a?(UndefinedStrategy) raise ArgumentError, "Cannot specify :overwrite when another strategy already defined" end @strategy = Strategies::Overwrite.new(@model_class, &block) end |
#skip_if(&if_condition) ⇒ Object
Prevent any anonymisation strategy being applied when the provided block evaluates to true. The block is executed in the model context.
96 97 98 99 100 |
# File 'lib/anony/model_config.rb', line 96 def skip_if(&if_condition) raise ArgumentError, "Block required for :skip_if" unless block_given? @skip_filter = if_condition end |