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

AVAILABLE_IN =
%w[Free Premium Ultimate].freeze
HYPHENATED_ATTRIBUTES =
[:self_managed, :gitlab_com].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entry) ⇒ Entry

Returns a new instance of Entry.



25
26
27
# File 'lib/release_highlights/validator/entry.rb', line 25

def initialize(entry)
  @entry = entry
end

Instance Attribute Details

#available_inObject

Returns the value of attribute available_in.



12
13
14
# File 'lib/release_highlights/validator/entry.rb', line 12

def available_in
  @available_in
end

#descriptionObject

Returns the value of attribute description.



12
13
14
# File 'lib/release_highlights/validator/entry.rb', line 12

def description
  @description
end

#entryObject (readonly)

Returns the value of attribute entry.



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

def entry
  @entry
end

#gitlab_comObject

Returns the value of attribute gitlab_com.



12
13
14
# File 'lib/release_highlights/validator/entry.rb', line 12

def gitlab_com
  @gitlab_com
end

#image_urlObject

Returns the value of attribute image_url.



12
13
14
# File 'lib/release_highlights/validator/entry.rb', line 12

def image_url
  @image_url
end

#nameObject

Returns the value of attribute name.



12
13
14
# File 'lib/release_highlights/validator/entry.rb', line 12

def name
  @name
end

#published_atObject

Returns the value of attribute published_at.



12
13
14
# File 'lib/release_highlights/validator/entry.rb', line 12

def published_at
  @published_at
end

#releaseObject

Returns the value of attribute release.



12
13
14
# File 'lib/release_highlights/validator/entry.rb', line 12

def release
  @release
end

#self_managedObject

Returns the value of attribute self_managed.



12
13
14
# File 'lib/release_highlights/validator/entry.rb', line 12

def self_managed
  @self_managed
end

#stageObject

Returns the value of attribute stage.



12
13
14
# File 'lib/release_highlights/validator/entry.rb', line 12

def stage
  @stage
end

Instance Method Details

#read_attribute_for_validation(key) ⇒ Object



45
46
47
# File 'lib/release_highlights/validator/entry.rb', line 45

def read_attribute_for_validation(key)
  value_for(key)
end

#validate_available_inObject



37
38
39
40
41
42
43
# File 'lib/release_highlights/validator/entry.rb', line 37

def validate_available_in
  available_in = value_for('available_in')

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

#validate_published_atObject



29
30
31
32
33
34
35
# File 'lib/release_highlights/validator/entry.rb', line 29

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