Class: Indexer::Validator
- 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, #date, #description, #engines, #install_message, #load_path, #name, #namespace, #organizations, #platforms, #repositories, #requirements, #resources, #revision, #sources, #suite, #summary, #title, #type, #version, #webcvs
Class Method Summary collapse
-
.new(data = {}) ⇒ Object
Revision factory returns a versioned instance of the model class.
-
.revise(data) ⇒ Object
Update metadata to current revision if using old revision.
-
.valid(data) ⇒ Object
Load metadata, ensuring canoncial validity.
Instance Method Summary collapse
- #alternatives=(value) ⇒ Object
-
#authors=(value) ⇒ Object
Authors must an array of hashes in the form of ‘{name: …, email: …, website: …, roles: […] }`.
- #categories=(value) ⇒ Object
-
#codename=(value) ⇒ Object
Codename must a single-line string.
-
#conflicts=(value) ⇒ Object
List of packages with which this project cannot function.
-
#copyrights=(value) ⇒ Object
Set sequence of copyrights mappings.
-
#created=(value) ⇒ Object
The creation date must be a valide UTC formatted date.
-
#date=(value) ⇒ Object
Date must be a UTC formated string, time is optional.
-
#description=(value) ⇒ Object
Description must be string.
-
#engines=(value) ⇒ Object
List of language engine/version family supported.
- #extra=(value) ⇒ Object
-
#install_message=(value) ⇒ Object
The post-installation message must be a String.
-
#load_path=(value) ⇒ Object
Loadpath must be an Array of valid pathnames or a String of pathnames separated by colons or semi-colons.
-
#name=(value) ⇒ Object
Project’s _packaging name_ must be a string without spaces using only ‘[a-zA-Z0-9_-]`.
-
#namespace=(value) ⇒ Object
Namespace must be a single line string.
-
#organizations=(value) ⇒ Object
Organizations must be an array of hashes in the form of ‘{name: …, email: …, website: …, roles: […] }`.
-
#platforms=(value) ⇒ Object
List of platforms supported.
-
#repositories=(value) ⇒ Object
Repositores must be a mapping of
name => URL
. -
#requirements=(value) ⇒ Object
Requirements must be a list of package references.
-
#resources=(value) ⇒ Object
Resources must be an array of hashes in the form of ‘…, name: …, type: …`.
- #revision=(value) ⇒ Object
-
#save!(file) ⇒ Object
By saving via the Validator, we help ensure only the canoncial form even makes it to disk.
-
#suite=(value) ⇒ Object
Suite must be a single line string.
-
#summary=(value) ⇒ Object
Summary must be a single-line string.
-
#title=(value) ⇒ Object
Title of package must be a single-line string.
-
#type=(value) ⇒ Object
Project’s type must be a string without spaces using only ‘[a-zA-Z0-9_-:/]`.
-
#valid? ⇒ Boolean
A specification is not valid without a name and verison.
- #version=(value) ⇒ Object
-
#webcvs=(value) ⇒ Object
The webcvs prefix must be a valid URI.
Methods included from Attributes
Methods inherited from Model
#[], #[]=, attr_reader, attr_writer, #initialize, #key?, #merge!, #method_missing, #to_h, #to_yaml
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.
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.
32 33 34 |
# File 'lib/indexer/validator.rb', line 32 def self.valid(data) new(data) end |
Instance Method Details
#alternatives=(value) ⇒ Object
152 153 154 155 |
# File 'lib/indexer/validator.rb', line 152 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: […] }`.
189 190 191 192 193 |
# File 'lib/indexer/validator.rb', line 189 def (value) Valid.array!(value, :authors) value.each{ |h| Valid.hash!(h, :authors) } super(value) end |
#categories=(value) ⇒ Object
160 161 162 163 164 165 166 |
# File 'lib/indexer/validator.rb', line 160 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.
143 144 145 146 147 148 149 |
# File 'lib/indexer/validator.rb', line 143 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.
181 182 183 184 185 |
# File 'lib/indexer/validator.rb', line 181 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.
175 176 177 178 |
# File 'lib/indexer/validator.rb', line 175 def created=(value) Valid.utc_date!(value, :created) 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.
113 114 115 116 |
# File 'lib/indexer/validator.rb', line 113 def engines=(value) Valid.array!(value) super(value) end |
#extra=(value) ⇒ Object
254 255 256 257 |
# File 'lib/indexer/validator.rb', line 254 def extra=(value) Valid.hash!(value, :extra) super(value) end |
#install_message=(value) ⇒ Object
The post-installation message must be a String.
225 226 227 228 |
# File 'lib/indexer/validator.rb', line 225 def (value) Valid.string!(value) super(value) end |
#load_path=(value) ⇒ Object
Loadpath must be an Array of valid pathnames or a String of pathnames separated by colons or semi-colons.
106 107 108 109 110 |
# File 'lib/indexer/validator.rb', line 106 def load_path=(value) Valid.array!(value, :load_path) value.each_with_index{ |path, i| Valid.path!(path, "load_path #{i}") } 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.
233 234 235 236 237 |
# File 'lib/indexer/validator.rb', line 233 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: […] }`.
197 198 199 200 201 |
# File 'lib/indexer/validator.rb', line 197 def organizations=(value) Valid.array!(value, :organizations) value.each{ |h| Valid.hash!(h, :organizations) } super(value) end |
#platforms=(value) ⇒ Object
List of platforms supported.
119 120 121 122 |
# File 'lib/indexer/validator.rb', line 119 def platforms=(value) Valid.array!(value) super(value) end |
#repositories=(value) ⇒ Object
Repositores must be a mapping of name => URL
.
212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/indexer/validator.rb', line 212 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.
125 126 127 128 129 130 131 |
# File 'lib/indexer/validator.rb', line 125 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 ‘…, name: …, type: …`.
205 206 207 208 209 |
# File 'lib/indexer/validator.rb', line 205 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.("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?
273 274 275 276 277 |
# File 'lib/indexer/validator.rb', line 273 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.
169 170 171 172 |
# File 'lib/indexer/validator.rb', line 169 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.
262 263 264 265 266 |
# File 'lib/indexer/validator.rb', line 262 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 |