Class: MonkeyLens::Policy::Waiver
- Inherits:
-
Object
- Object
- MonkeyLens::Policy::Waiver
- Defined in:
- lib/monkey_lens/policy.rb
Instance Attribute Summary collapse
-
#expires_on ⇒ Object
readonly
Returns the value of attribute expires_on.
-
#method_pattern ⇒ Object
readonly
Returns the value of attribute method_pattern.
-
#reason ⇒ Object
readonly
Returns the value of attribute reason.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #expired?(today: Date.today) ⇒ Boolean
-
#initialize(type: "*", target: "*", method: "*", reason:, expires_on: nil) ⇒ Waiver
constructor
A new instance of Waiver.
- #match?(change, today: Date.today) ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(type: "*", target: "*", method: "*", reason:, expires_on: nil) ⇒ Waiver
Returns a new instance of Waiver.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/monkey_lens/policy.rb', line 11 def initialize(type: "*", target: "*", method: "*", reason:, expires_on: nil) raise ConfigurationError, "waiver reason is required" if reason.to_s.strip.empty? @type = type.to_s @target = target.to_s @method_pattern = method.to_s @reason = reason.to_s @expires_on = expires_on && Date.iso8601(expires_on.to_s) rescue Date::Error raise ConfigurationError, "invalid waiver expiration #{expires_on.inspect}" end |
Instance Attribute Details
#expires_on ⇒ Object (readonly)
Returns the value of attribute expires_on.
9 10 11 |
# File 'lib/monkey_lens/policy.rb', line 9 def expires_on @expires_on end |
#method_pattern ⇒ Object (readonly)
Returns the value of attribute method_pattern.
9 10 11 |
# File 'lib/monkey_lens/policy.rb', line 9 def method_pattern @method_pattern end |
#reason ⇒ Object (readonly)
Returns the value of attribute reason.
9 10 11 |
# File 'lib/monkey_lens/policy.rb', line 9 def reason @reason end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
9 10 11 |
# File 'lib/monkey_lens/policy.rb', line 9 def target @target end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
9 10 11 |
# File 'lib/monkey_lens/policy.rb', line 9 def type @type end |
Instance Method Details
#expired?(today: Date.today) ⇒ Boolean
31 32 33 |
# File 'lib/monkey_lens/policy.rb', line 31 def expired?(today: Date.today) expires_on && expires_on < today end |
#match?(change, today: Date.today) ⇒ Boolean
23 24 25 26 27 28 29 |
# File 'lib/monkey_lens/policy.rb', line 23 def match?(change, today: Date.today) return false if expired?(today:) matches?(type, change.type) && matches?(target, change.target) && matches?(method_pattern, change.method_id.to_s) end |
#to_h ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/monkey_lens/policy.rb', line 35 def to_h { "type" => type, "target" => target, "method" => method_pattern, "reason" => reason, "expires_on" => expires_on&.iso8601 }.compact end |