Class: Entitlement::Entry
- Inherits:
-
Object
- Object
- Entitlement::Entry
- Defined in:
- lib/entitlement/entry.rb
Overview
Base class for all entitlement entries
Direct Known Subclasses
CustomEntry, DomainsEntry, NodesEntry, NumberedEntry, OpenSourceEntry, PayPerUse, SizedEntry, UsageOnlyEntry
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
Instance Method Summary collapse
- #days_left ⇒ Object
- #expiring? ⇒ Boolean
-
#initialize(modules, from = nil, to = nil, filename_string = nil, &proc) ⇒ Entry
constructor
A new instance of Entry.
-
#inspect ⇒ Object
rubocop: enable Metrics/CyclomaticComplexity.
-
#notify_if_expiring(module_name) ⇒ Object
rubocop:enable Style/GlobalVars.
- #purgable? ⇒ Boolean
-
#valid?(module_name, resources = nil) ⇒ Boolean
rubocop: disable Metrics/CyclomaticComplexity.
Constructor Details
#initialize(modules, from = nil, to = nil, filename_string = nil, &proc) ⇒ Entry
Returns a new instance of Entry.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/entitlement/entry.rb', line 13 def initialize(modules, from = nil, to = nil, filename_string = nil, &proc) # rubocop:disable Style/GlobalVars @file = $entitlements_file @warning_period = 30 @modules = modules.to_a @from = from @to = to @filename_string = filename_string @validator = proc end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
11 12 13 |
# File 'lib/entitlement/entry.rb', line 11 def file @file end |
Instance Method Details
#days_left ⇒ Object
62 63 64 |
# File 'lib/entitlement/entry.rb', line 62 def days_left @to - Date.today end |
#expiring? ⇒ Boolean
58 59 60 |
# File 'lib/entitlement/entry.rb', line 58 def expiring? @to && @to <= (Date.today + @warning_period) end |
#inspect ⇒ Object
rubocop: enable Metrics/CyclomaticComplexity
50 51 52 53 54 55 56 |
# File 'lib/entitlement/entry.rb', line 50 def inspect puts "Lic. File : #{@file}" puts "modules : #{@modules.join(',')}" puts "From date : #{@from}" if @from puts "To date : #{@to}" if @to puts "Purgable : #{purgable? ? 'yes' : 'no'}" end |
#notify_if_expiring(module_name) ⇒ Object
rubocop:enable Style/GlobalVars
25 26 27 28 29 30 |
# File 'lib/entitlement/entry.rb', line 25 def notify_if_expiring(module_name) return unless expiring? && valid?(module_name) && !@expire_message_printed @expire_message_printed = true Puppet.alert "*WARNING* : Only #{days_left.round} days left until your entitlement for module #{module_name} on current node is expiring. Take appropriate action." # rubocop:enable Metrics/LineLength end |
#purgable? ⇒ Boolean
32 33 34 |
# File 'lib/entitlement/entry.rb', line 32 def purgable? @to && @to <= Date.today end |
#valid?(module_name, resources = nil) ⇒ Boolean
rubocop: disable Metrics/CyclomaticComplexity
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/entitlement/entry.rb', line 37 def valid?(module_name, resources = nil) # If the entitlement file is in the older version, do not perform check if @filename_string return false unless filename_match? end return false if @from && @from > Date.today return false if @to && @to <= Date.today return false unless matching_module(module_name) return true unless @validator @validator.call(resources) end |