Module: Radio5::Validations

Extended by:
Matchers
Included in:
Client
Defined in:
lib/radio5/validations.rb,
lib/radio5/validations/regexps.rb,
lib/radio5/validations/matchers.rb

Defined Under Namespace

Modules: Matchers, Regexps

Class Method Summary collapse

Methods included from Matchers

country_iso_code?, decade?, mongo_id?, mood?, positive_number?, user_track_status?

Class Method Details

.validate!Object



10
11
12
13
14
# File 'lib/radio5/validations.rb', line 10

def validate!
  yield

  true
end

.validate_country_iso_code!(object) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/radio5/validations.rb', line 52

def validate_country_iso_code!(object)
  validate! do
    unless country_iso_code?(object)
      raise ArgumentError, "invalid country ISO code: #{object.inspect}"
    end
  end
end

.validate_country_iso_codes!(iso_codes) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/radio5/validations.rb', line 40

def validate_country_iso_codes!(iso_codes)
  validate! do
    unless iso_codes.is_a?(Array)
      raise ArgumentError, "country ISO codes should be an array: #{iso_codes.inspect}"
    end

    iso_codes.each do |iso_code|
      validate_country_iso_code!(iso_code)
    end
  end
end

.validate_decade!(object) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/radio5/validations.rb', line 72

def validate_decade!(object)
  validate! do
    unless decade?(object)
      raise ArgumentError, "invalid decade: #{object.inspect}"
    end
  end
end

.validate_decades!(decades) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/radio5/validations.rb', line 60

def validate_decades!(decades)
  validate! do
    unless decades.is_a?(Array)
      raise ArgumentError, "decades should be an array: #{decades.inspect}"
    end

    decades.each do |decade|
      validate_decade!(decade)
    end
  end
end

.validate_island_id!(object) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/radio5/validations.rb', line 32

def validate_island_id!(object)
  validate! do
    unless mongo_id?(object)
      raise ArgumentError, "invalid island ID: #{object.inspect}"
    end
  end
end

.validate_mood!(object) ⇒ Object



92
93
94
95
96
97
98
# File 'lib/radio5/validations.rb', line 92

def validate_mood!(object)
  validate! do
    unless mood?(object)
      raise ArgumentError, "invalid mood: #{object.inspect}"
    end
  end
end

.validate_moods!(moods) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/radio5/validations.rb', line 80

def validate_moods!(moods)
  validate! do
    unless moods.is_a?(Array)
      raise ArgumentError, "moods should be an array: #{moods.inspect}"
    end

    moods.each do |mood|
      validate_mood!(mood)
    end
  end
end

.validate_page_number!(object) ⇒ Object



116
117
118
119
120
121
122
# File 'lib/radio5/validations.rb', line 116

def validate_page_number!(object)
  validate! do
    unless positive_number?(object)
      raise ArgumentError, "invalid page number: #{object.inspect}"
    end
  end
end

.validate_page_size!(object) ⇒ Object



108
109
110
111
112
113
114
# File 'lib/radio5/validations.rb', line 108

def validate_page_size!(object)
  validate! do
    unless positive_number?(object)
      raise ArgumentError, "invalid page size: #{object.inspect}"
    end
  end
end

.validate_track_id!(object) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/radio5/validations.rb', line 24

def validate_track_id!(object)
  validate! do
    unless mongo_id?(object)
      raise ArgumentError, "invalid track ID: #{object.inspect}"
    end
  end
end

.validate_user_id!(object) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/radio5/validations.rb', line 16

def validate_user_id!(object)
  validate! do
    unless mongo_id?(object)
      raise ArgumentError, "invalid user ID: #{object.inspect}"
    end
  end
end

.validate_user_track_status!(object) ⇒ Object



100
101
102
103
104
105
106
# File 'lib/radio5/validations.rb', line 100

def validate_user_track_status!(object)
  validate! do
    unless user_track_status?(object)
      raise ArgumentError, "invalid user track status: #{object.inspect}"
    end
  end
end