Class: ReleaseHighlights::Validator::Entry

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations, ActiveModel::Validations::Callbacks
Defined in:
lib/release_highlights/validator/entry.rb

Constant Summary collapse

PACKAGES =
%w(Free Premium Ultimate).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entry) ⇒ Entry

Returns a new instance of Entry.


21
22
23
# File 'lib/release_highlights/validator/entry.rb', line 21

def initialize(entry)
  @entry = entry
end

Instance Attribute Details

#entryObject (readonly)

Returns the value of attribute entry.


10
11
12
# File 'lib/release_highlights/validator/entry.rb', line 10

def entry
  @entry
end

Instance Method Details

#read_attribute_for_validation(key) ⇒ Object


41
42
43
# File 'lib/release_highlights/validator/entry.rb', line 41

def read_attribute_for_validation(key)
  value_for(key)
end

#validate_packagesObject


33
34
35
36
37
38
39
# File 'lib/release_highlights/validator/entry.rb', line 33

def validate_packages
  packages = value_for('packages')

  if !packages.is_a?(Array) || packages.empty? || packages.any? { |p| PACKAGES.exclude?(p) }
    errors.add(:packages, "must be one of #{PACKAGES}")
  end
end

#validate_published_atObject


25
26
27
28
29
30
31
# File 'lib/release_highlights/validator/entry.rb', line 25

def validate_published_at
  published_at = value_for('published_at')

  return if published_at.is_a?(Date)

  errors.add(:published_at, 'must be valid Date')
end