Class: Indexer::Validator

Inherits:
Model
  • Object
show all
Includes:
Attributes
Defined in:
lib/indexer/validator.rb

Overview

Validator class models the strict canonical specification of the index file format. It is a one-to-one mapping with no method aliases or other conveniences.

Instance Attribute Summary

Attributes included from Attributes

#alternatives, #authors, #categories, #codename, #conflicts, #copyrights, #created, #customs, #date, #description, #engines, #install_message, #name, #namespace, #organizations, #paths, #platforms, #repositories, #requirements, #resources, #revision, #sources, #suite, #summary, #title, #type, #version, #webcvs

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Attributes

attr_accessor, #attributes

Methods inherited from Model

#[], #[]=, attr_reader, attr_writer, #initialize, #key?, #merge!, #method_missing, #store, #to_h, #to_yaml, #validate

Constructor Details

This class inherits a constructor from Indexer::Model

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Indexer::Model

Class Method Details

.new(data = {}) ⇒ Object

Revision factory returns a versioned instance of the model class.

Parameters:

  • data (Hash) (defaults to: {})

    The data to populate the instance.



21
22
23
24
# File 'lib/indexer/validator.rb', line 21

def self.new(data={})
  data = revise(data)
  super(data)
end

.revise(data) ⇒ Object

Update metadata to current revision if using old revision.



39
40
41
# File 'lib/indexer/validator.rb', line 39

def self.revise(data)
  Revision.upconvert(data)
end

.valid(data) ⇒ Object

Load metadata, ensuring canoncial validity.

Parameters:

  • data (String)

    The data to be validate and then to populate the instance.



32
33
34
# File 'lib/indexer/validator.rb', line 32

def self.valid(data)
  new(data)
end

Instance Method Details

#alternatives=(value) ⇒ Object



153
154
155
156
# File 'lib/indexer/validator.rb', line 153

def alternatives=(value)
  Valid.array!(value, :alternatives)
  super(value)
end

#authors=(value) ⇒ Object

Authors must an array of hashes in the form of {name: ..., email: ..., website: ..., roles: [...] }.



190
191
192
193
194
# File 'lib/indexer/validator.rb', line 190

def authors=(value)
  Valid.array!(value, :authors)
  value.each{ |h| Valid.hash!(h, :authors) }
  super(value)
end

#categories=(value) ⇒ Object



161
162
163
164
165
166
167
# File 'lib/indexer/validator.rb', line 161

def categories=(value)
  Valid.array!(value, :categories)
  value.each_with_index do |c, i|
    Valid.oneline!(c, "categories #{i}")
  end
  super(value)
end

#codename=(value) ⇒ Object

Codename must a single-line string.



99
100
101
102
# File 'lib/indexer/validator.rb', line 99

def codename=(value)
  Valid.oneline!(value, :codename)
  super(value)
end

#conflicts=(value) ⇒ Object

List of packages with which this project cannot function.



144
145
146
147
148
149
150
# File 'lib/indexer/validator.rb', line 144

def conflicts=(value)
  Valid.array!(value, :conflicts)
  value.each_with_index do |c, i|
    Valid.hash!(c, "conflicts #{i}")
  end
  super(value)
end

#copyrights=(value) ⇒ Object

Set sequence of copyrights mappings.



182
183
184
185
186
# File 'lib/indexer/validator.rb', line 182

def copyrights=(value)
  Valid.array!(value, :copyrights)
  value.each{ |h| Valid.hash!(h, :copyrights) }
  super(value)
end

#created=(value) ⇒ Object

The creation date must be a valide UTC formatted date.



176
177
178
179
# File 'lib/indexer/validator.rb', line 176

def created=(value)
  Valid.utc_date!(value, :created)
  super(value)
end

#customs=(value) ⇒ Object

Custom field names must a valid list of strings.



255
256
257
258
259
260
261
# File 'lib/indexer/validator.rb', line 255

def customs=(value)
  Valid.array!(value, :customs)
  value.each_with_index do |data, index|
    Valid.string!(data, "customs ##{index}")
  end
  super(value)
end

#date=(value) ⇒ Object

Date must be a UTC formated string, time is optional.



75
76
77
78
# File 'lib/indexer/validator.rb', line 75

def date=(value)
  Valid.utc_date!(value, :date)
  super(value)
end

#description=(value) ⇒ Object

Description must be string.



93
94
95
96
# File 'lib/indexer/validator.rb', line 93

def description=(value)
  Valid.string!(value, :description)
  super(value)
end

#engines=(value) ⇒ Object

List of language engine/version family supported.



114
115
116
117
# File 'lib/indexer/validator.rb', line 114

def engines=(value)
  Valid.array!(value)
  super(value)
end

#install_message=(value) ⇒ Object

The post-installation message must be a String.



226
227
228
229
# File 'lib/indexer/validator.rb', line 226

def install_message=(value)
  Valid.string!(value)
  super(value)
end

#name=(value) ⇒ Object

Project's packaging name must be a string without spaces using only [a-zA-Z0-9_-].



63
64
65
66
# File 'lib/indexer/validator.rb', line 63

def name=(value)
  Valid.name!(value, :name)
  super(value)
end

#namespace=(value) ⇒ Object

Namespace must be a single line string.



234
235
236
237
238
# File 'lib/indexer/validator.rb', line 234

def namespace=(value)
  Valid.oneline!(value, :namespace)
  #raise ValidationError unless /^(class|module)/ =~ value
  super(value)
end

#organizations=(value) ⇒ Object

Organizations must be an array of hashes in the form of {name: ..., email: ..., website: ..., roles: [...] }.



198
199
200
201
202
# File 'lib/indexer/validator.rb', line 198

def organizations=(value)
  Valid.array!(value, :organizations)
  value.each{ |h| Valid.hash!(h, :organizations) }
  super(value)
end

#paths=(value) ⇒ Object

Paths must be a Hash of names mapped to an Array of valid pathnames.



105
106
107
108
109
110
111
# File 'lib/indexer/validator.rb', line 105

def paths=(value)
  Valid.hash!(value, :paths)
  value.each do |name, paths|
    paths.each_with_index{ |path, i| Valid.path!(path, "paths[#{name}] ##{i}") }
  end
  super(value)
end

#platforms=(value) ⇒ Object

List of platforms supported.



120
121
122
123
# File 'lib/indexer/validator.rb', line 120

def platforms=(value)
  Valid.array!(value)
  super(value)          
end

#repositories=(value) ⇒ Object

Repositores must be a mapping of name => URL.



213
214
215
216
217
218
219
220
221
222
223
# File 'lib/indexer/validator.rb', line 213

def repositories=(value)
  Valid.array! value, :repositories
  value.each_with_index do |data, index|
    Valid.hash! data, "repositories #{index}"
    #Valid.uri!  data['uri'], "repositories ##{index}"
    Valid.oneline! data['uri'], "repositories ##{index}"
    Valid.oneline! data['id'],  "repositories ##{index}" if data['id']
    Valid.word!    data['scm'], "repositories ##{index}" if data['scm']
  end
  super value
end

#requirements=(value) ⇒ Object

Requirements must be a list of package references.



126
127
128
129
130
131
132
# File 'lib/indexer/validator.rb', line 126

def requirements=(value)
  Valid.array!(value, :requirements)
  value.each_with_index do |r, i|
    Valid.hash!(r, "requirements #{i}")
  end
  super(value)
end

#resources=(value) ⇒ Object

Resources must be an array of hashes in the form of {uri: ..., name: ..., type: ...}.



206
207
208
209
210
# File 'lib/indexer/validator.rb', line 206

def resources=(value)
  Valid.array!(value, :resources)
  value.each{ |h| Valid.hash!(h, :resources) }
  super(value)
end

#revision=(value) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/indexer/validator.rb', line 46

def revision=(value)
  if value.to_i != REVISION
    # technically this should never happen
    Valid.raise_invalid_message("revision is not current #{REVISION} -- #{value}")
  end
  super(value)
end

#save!(file) ⇒ Object

By saving via the Validator, we help ensure only the canoncial form even makes it to disk.

TODO: Only save when when different?



277
278
279
280
281
# File 'lib/indexer/validator.rb', line 277

def save!(file)
  File.open(file, 'w') do |f|
    f << to_h.to_yaml
  end
end

#suite=(value) ⇒ Object

Suite must be a single line string.



170
171
172
173
# File 'lib/indexer/validator.rb', line 170

def suite=(value)
  Valid.oneline!(value, :suite)
  super(value)
end

#summary=(value) ⇒ Object

Summary must be a single-line string.



87
88
89
90
# File 'lib/indexer/validator.rb', line 87

def summary=(value)
  Valid.oneline!(value, :summary)
  super(value)
end

#title=(value) ⇒ Object

Title of package must be a single-line string.



81
82
83
84
# File 'lib/indexer/validator.rb', line 81

def title=(value)
  Valid.oneline!(value, :title)
  super(value)
end

#type=(value) ⇒ Object

Project's type must be a string without spaces using only [a-zA-Z0-9_-:/].



56
57
58
59
# File 'lib/indexer/validator.rb', line 56

def type=(value)
  Valid.type!(value, :type)
  super(value)
end

#valid?Boolean

A specification is not valid without a name and verison.

Returns:

  • (Boolean)

    valid specification?



266
267
268
269
270
# File 'lib/indexer/validator.rb', line 266

def valid?
  return false unless name
  return false unless version
  true
end

#version=(value) ⇒ Object



69
70
71
72
# File 'lib/indexer/validator.rb', line 69

def version=(value)
  validate(value, :version, :version_string!)
  super(value)
end

#webcvs=(value) ⇒ Object

The webcvs prefix must be a valid URI.



249
250
251
252
# File 'lib/indexer/validator.rb', line 249

def webcvs=(value)
  Valid.uri!(value, :webcvs)
  super(value)
end