Class: Ast::Merge::Ruleset::LogicalOwnerPolicy
- Inherits:
-
Object
- Object
- Ast::Merge::Ruleset::LogicalOwnerPolicy
- Defined in:
- lib/ast/merge/ruleset/logical_owner_policy.rb
Overview
Declarative policy for a logical owner kind.
Constant Summary collapse
- PRESERVE_ALWAYS =
:preserve_always- PRESERVE_IF_REFERENCED =
:preserve_if_referenced- REMOVE_UNREFERENCED =
:remove_unreferenced- ACTIONS =
[PRESERVE_ALWAYS, PRESERVE_IF_REFERENCED, REMOVE_UNREFERENCED].freeze
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
Instance Method Summary collapse
-
#initialize(kind:, action:, metadata: {}, **options) ⇒ LogicalOwnerPolicy
constructor
A new instance of LogicalOwnerPolicy.
- #preserve?(referenced:) ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(kind:, action:, metadata: {}, **options) ⇒ LogicalOwnerPolicy
Returns a new instance of LogicalOwnerPolicy.
15 16 17 18 19 |
# File 'lib/ast/merge/ruleset/logical_owner_policy.rb', line 15 def initialize(kind:, action:, metadata: {}, **) @kind = kind.to_sym @action = normalize_action(action) @metadata = .merge().freeze end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
13 14 15 |
# File 'lib/ast/merge/ruleset/logical_owner_policy.rb', line 13 def action @action end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
13 14 15 |
# File 'lib/ast/merge/ruleset/logical_owner_policy.rb', line 13 def kind @kind end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
13 14 15 |
# File 'lib/ast/merge/ruleset/logical_owner_policy.rb', line 13 def @metadata end |
Instance Method Details
#preserve?(referenced:) ⇒ Boolean
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ast/merge/ruleset/logical_owner_policy.rb', line 21 def preserve?(referenced:) case action when PRESERVE_ALWAYS true when PRESERVE_IF_REFERENCED referenced when REMOVE_UNREFERENCED referenced else false end end |
#to_h ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/ast/merge/ruleset/logical_owner_policy.rb', line 34 def to_h { kind: kind, action: action, metadata: } end |