rcap 2.3.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +4 -0
- data/README.md +12 -12
- data/lib/assistance/extract_options.rb +14 -0
- data/lib/assistance/validation.rb +251 -0
- data/lib/rcap/extensions/array.rb +4 -0
- data/lib/rcap/extensions/date_time.rb +4 -0
- data/lib/rcap/extensions/fixnum.rb +5 -0
- data/lib/rcap/extensions/float.rb +5 -0
- data/lib/rcap/extensions/nil_class.rb +5 -0
- data/lib/rcap/extensions/string.rb +4 -0
- data/lib/rcap/version.rb +1 -1
- data/lib/rcap.rb +7 -1
- data/rcap.gemspec +0 -1
- data/spec/alert_spec.rb +1 -1
- metadata +7 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 548ad24cc10525bee68f71efb84786a0f490419f
|
4
|
+
data.tar.gz: 4baf6cbd9b0b98973f139181d69a968b3c16dc50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11bf3c92150c6ce9585e675208ce7553427e83c10de6a0d91fa50919c038eba254c2eefaf7902fedccb60109949d2f2a58eecb3297fa28ea526498be8e92b50f
|
7
|
+
data.tar.gz: e0660c2f73fd50bdd268221b496e32d018a2a86c55734ca31ec3c11e66bddad4445eea4efd6de6c92739812203b19a7eae1da19470447d76090483d75631c217
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -13,7 +13,6 @@ Dependencies
|
|
13
13
|
|
14
14
|
RCAP depends on the following gems
|
15
15
|
|
16
|
-
* [Assistance](http://assistance.rubyforge.org)
|
17
16
|
* [UUIDTools](http://uuidtools.rubyforge.org)
|
18
17
|
* [JSON](http://json.rubyforge.org)
|
19
18
|
|
@@ -33,7 +32,7 @@ Usage
|
|
33
32
|
|
34
33
|
### Creating an Alert
|
35
34
|
|
36
|
-
RCAP uses a 'builder' style syntax to create alerts.
|
35
|
+
RCAP uses a 'builder' style syntax to create alerts.
|
37
36
|
|
38
37
|
require 'rcap'
|
39
38
|
|
@@ -41,13 +40,13 @@ RCAP uses a 'builder' style syntax to create alerts.
|
|
41
40
|
alert.sender = 'cape_town_disaster_relief@capetown.municipal.za'
|
42
41
|
alert.status = Alert::STATUS_ACTUAL
|
43
42
|
alert.msg_type = Alert::MSG_TYPE_ALERT
|
44
|
-
alert.scope = Alert::SCOPE_PUBLIC
|
45
|
-
|
43
|
+
alert.scope = Alert::SCOPE_PUBLIC
|
44
|
+
|
46
45
|
alert.add_info do |info|
|
47
46
|
info.event = 'Liquid Petroleoum Tanker Fire'
|
48
47
|
info.language = 'en-ZA'
|
49
48
|
info.categories << Info::CATEGORY_TRANSPORT
|
50
|
-
info.categories << Info::CATEGORY_FIRE
|
49
|
+
info.categories << Info::CATEGORY_FIRE
|
51
50
|
info.urgency = Info::URGENCY_IMMEDIATE
|
52
51
|
info.severity = Info::SEVERITY_SEVERE
|
53
52
|
info.certainty = Info::CERTAINTY_OBSERVED
|
@@ -55,18 +54,18 @@ RCAP uses a 'builder' style syntax to create alerts.
|
|
55
54
|
info.description = 'A liquid petroleoum tanker has caught fire on the N2 incoming freeway 1km
|
56
55
|
after the R300 interchange. Municipal fire fighting crews have been dispatched.
|
57
56
|
Traffic control officers are on the scene and have diverted traffic onto
|
58
|
-
alternate routes.'
|
59
|
-
|
57
|
+
alternate routes.'
|
58
|
+
|
60
59
|
info.add_area do |area|
|
61
|
-
area.area_desc = 'N2 Highway/R300 Interchange'
|
60
|
+
area.area_desc = 'N2 Highway/R300 Interchange'
|
62
61
|
area.add_geocode do |geocode|
|
63
62
|
geocode.name = 'Intersection'
|
64
|
-
geocode.value = 'N2-15'
|
63
|
+
geocode.value = 'N2-15'
|
65
64
|
end
|
66
65
|
end
|
67
66
|
end
|
68
67
|
end
|
69
|
-
|
68
|
+
|
70
69
|
# Accessing attributes
|
71
70
|
puts alert.status # "Actual"
|
72
71
|
info = alert.infos.first
|
@@ -128,7 +127,7 @@ The RCAP API aims to codify as many of the rules of the CAP XML format into vali
|
|
128
127
|
info.severity = nil # Severity is not assigned
|
129
128
|
info.certainty = 'Incorrect Certainty' # Certainty is assigned an incorrect value
|
130
129
|
end
|
131
|
-
|
130
|
+
|
132
131
|
puts "Is info valid: #{ info.valid? }"
|
133
132
|
info.errors.full_messages.each{ |message| puts "Error: #{ message }" }
|
134
133
|
|
@@ -146,7 +145,7 @@ Web resources
|
|
146
145
|
* The RCAP project page can be found at [http://www.aimred.com/projects/rcap](http://www.aimred.com/projects/rcap)
|
147
146
|
* The RCAP API docs can be found at [http://www.aimred.com/projects/rcap/api](http://www.aimred.com/projects/rcap/api)
|
148
147
|
* A public git repository can be found at [http://github.com/farrel/RCAP](http://github.com/farrel/RCAP)
|
149
|
-
* A CAP Validator based on RCAP can be found at [http://capvalidator.
|
148
|
+
* A CAP Validator based on RCAP can be found at [http://capvalidator.herokuapp.com](http://capvalidator.herokuapp.com)
|
150
149
|
|
151
150
|
Authors
|
152
151
|
-------
|
@@ -156,6 +155,7 @@ Authors
|
|
156
155
|
### Contributors
|
157
156
|
|
158
157
|
* Earle Clubb - http://github.com/eclubb
|
158
|
+
* David van Geest - https://github.com/DWvanGeest
|
159
159
|
|
160
160
|
Change Log
|
161
161
|
----------
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Array extensions
|
2
|
+
class Array
|
3
|
+
# Removes and returns the last member of the array if it is a hash. Otherwise,
|
4
|
+
# an empty hash is returned This method is useful when writing methods that
|
5
|
+
# take an options hash as the last parameter. For example:
|
6
|
+
#
|
7
|
+
# def validate_each(*args, &block)
|
8
|
+
# opts = args.extract_options!
|
9
|
+
# ...
|
10
|
+
# end
|
11
|
+
def extract_options!
|
12
|
+
last.is_a?(Hash) ? pop : {}
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,251 @@
|
|
1
|
+
# This file is ripped directly from the no-longer-maintained assistance gem. Other code in that gem
|
2
|
+
# was causing issues, so I'm putting the needed code directly in rcap as a workaround.
|
3
|
+
|
4
|
+
# See https://github.com/farrel/RCAP/issues/4
|
5
|
+
|
6
|
+
# The Validations module provides validation capabilities as a mixin. When
|
7
|
+
# included into a class, it enhances the class with class and instance
|
8
|
+
# methods for defining validations and validating class instances.
|
9
|
+
#
|
10
|
+
# The Validation emulates the validation capabilities of ActiveRecord, and
|
11
|
+
# provides methods for validating acceptance, confirmation, presence, format,
|
12
|
+
# length and numericality of attributes.
|
13
|
+
#
|
14
|
+
# To use validations, you need to include the Validation module in your
|
15
|
+
# class:
|
16
|
+
#
|
17
|
+
# class MyClass
|
18
|
+
# include Validation
|
19
|
+
# validates_length_of :password, :minimum => 6
|
20
|
+
# end
|
21
|
+
module Validation
|
22
|
+
# Includes the Validation class methods into the including class.
|
23
|
+
def self.included(c)
|
24
|
+
c.extend ClassMethods
|
25
|
+
end
|
26
|
+
|
27
|
+
# Returns the validation errors associated with the object.
|
28
|
+
def errors
|
29
|
+
@errors ||= Errors.new
|
30
|
+
end
|
31
|
+
|
32
|
+
# Validates the object.
|
33
|
+
def validate
|
34
|
+
errors.clear
|
35
|
+
self.class.validate(self)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Validates the object and returns true if no errors are reported.
|
39
|
+
def valid?
|
40
|
+
validate
|
41
|
+
errors.empty?
|
42
|
+
end
|
43
|
+
|
44
|
+
# Validation::Errors represents validation errors.
|
45
|
+
class Errors
|
46
|
+
# Initializes a new instance of validation errors.
|
47
|
+
def initialize
|
48
|
+
@errors = Hash.new {|h, k| h[k] = []}
|
49
|
+
end
|
50
|
+
|
51
|
+
# Returns true if no errors are stored.
|
52
|
+
def empty?
|
53
|
+
@errors.empty?
|
54
|
+
end
|
55
|
+
|
56
|
+
# Clears all errors.
|
57
|
+
def clear
|
58
|
+
@errors.clear
|
59
|
+
end
|
60
|
+
|
61
|
+
# Returns the errors for the given attribute.
|
62
|
+
def on(att)
|
63
|
+
@errors[att]
|
64
|
+
end
|
65
|
+
alias_method :[], :on
|
66
|
+
|
67
|
+
# Adds an error for the given attribute.
|
68
|
+
def add(att, msg)
|
69
|
+
@errors[att] << msg
|
70
|
+
end
|
71
|
+
|
72
|
+
# Returns an array of fully-formatted error messages.
|
73
|
+
def full_messages
|
74
|
+
@errors.inject([]) do |m, kv| att, errors = *kv
|
75
|
+
errors.each {|e| m << "#{att} #{e}"}
|
76
|
+
m
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# The Generator class is used to generate validation definitions using
|
82
|
+
# the validates {} idiom.
|
83
|
+
class Generator
|
84
|
+
# Initializes a new generator.
|
85
|
+
def initialize(receiver ,&block)
|
86
|
+
@receiver = receiver
|
87
|
+
instance_eval(&block)
|
88
|
+
end
|
89
|
+
|
90
|
+
# Delegates method calls to the receiver by calling receiver.validates_xxx.
|
91
|
+
def method_missing(m, *args, &block)
|
92
|
+
@receiver.send(:"validates_#{m}", *args, &block)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# Validation class methods.
|
97
|
+
module ClassMethods
|
98
|
+
# Defines validations by converting a longhand block into a series of
|
99
|
+
# shorthand definitions. For example:
|
100
|
+
#
|
101
|
+
# class MyClass
|
102
|
+
# include Validation
|
103
|
+
# validates do
|
104
|
+
# length_of :name, :minimum => 6
|
105
|
+
# length_of :password, :minimum => 8
|
106
|
+
# end
|
107
|
+
# end
|
108
|
+
#
|
109
|
+
# is equivalent to:
|
110
|
+
# class MyClass
|
111
|
+
# include Validation
|
112
|
+
# validates_length_of :name, :minimum => 6
|
113
|
+
# validates_length_of :password, :minimum => 8
|
114
|
+
# end
|
115
|
+
def validates(&block)
|
116
|
+
Generator.new(self, &block)
|
117
|
+
end
|
118
|
+
|
119
|
+
# Returns the validations hash for the class.
|
120
|
+
def validations
|
121
|
+
@validations ||= Hash.new {|h, k| h[k] = []}
|
122
|
+
end
|
123
|
+
|
124
|
+
# Returns true if validations are defined.
|
125
|
+
def has_validations?
|
126
|
+
!validations.empty?
|
127
|
+
end
|
128
|
+
|
129
|
+
# Validates the given instance.
|
130
|
+
def validate(o)
|
131
|
+
if superclass.respond_to?(:validate) && !@skip_superclass_validations
|
132
|
+
superclass.validate(o)
|
133
|
+
end
|
134
|
+
validations.each do |att, procs|
|
135
|
+
v = o.send(att)
|
136
|
+
procs.each {|p| p[o, att, v]}
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def skip_superclass_validations
|
141
|
+
@skip_superclass_validations = true
|
142
|
+
end
|
143
|
+
|
144
|
+
# Adds a validation for each of the given attributes using the supplied
|
145
|
+
# block. The block must accept three arguments: instance, attribute and
|
146
|
+
# value, e.g.:
|
147
|
+
#
|
148
|
+
# validates_each :name, :password do |object, attribute, value|
|
149
|
+
# object.errors[attribute] << 'is not nice' unless value.nice?
|
150
|
+
# end
|
151
|
+
def validates_each(*atts, &block)
|
152
|
+
atts.each {|a| validations[a] << block}
|
153
|
+
end
|
154
|
+
|
155
|
+
# Validates acceptance of an attribute.
|
156
|
+
def validates_acceptance_of(*atts)
|
157
|
+
opts = {
|
158
|
+
:message => 'is not accepted',
|
159
|
+
:allow_nil => true,
|
160
|
+
:accept => '1'
|
161
|
+
}.merge!(atts.extract_options!)
|
162
|
+
|
163
|
+
validates_each(*atts) do |o, a, v|
|
164
|
+
next if (v.nil? && opts[:allow_nil]) || (v.blank? && opts[:allow_blank])
|
165
|
+
o.errors[a] << opts[:message] unless v == opts[:accept]
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
# Validates confirmation of an attribute.
|
170
|
+
def validates_confirmation_of(*atts)
|
171
|
+
opts = {
|
172
|
+
:message => 'is not confirmed',
|
173
|
+
}.merge!(atts.extract_options!)
|
174
|
+
|
175
|
+
validates_each(*atts) do |o, a, v|
|
176
|
+
next if (v.nil? && opts[:allow_nil]) || (v.blank? && opts[:allow_blank])
|
177
|
+
c = o.send(:"#{a}_confirmation")
|
178
|
+
o.errors[a] << opts[:message] unless v == c
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
# Validates the format of an attribute.
|
183
|
+
def validates_format_of(*atts)
|
184
|
+
opts = {
|
185
|
+
:message => 'is invalid',
|
186
|
+
}.merge!(atts.extract_options!)
|
187
|
+
|
188
|
+
unless opts[:with].is_a?(Regexp)
|
189
|
+
raise ArgumentError, "A regular expression must be supplied as the :with option of the options hash"
|
190
|
+
end
|
191
|
+
|
192
|
+
validates_each(*atts) do |o, a, v|
|
193
|
+
next if (v.nil? && opts[:allow_nil]) || (v.blank? && opts[:allow_blank])
|
194
|
+
o.errors[a] << opts[:message] unless v.to_s =~ opts[:with]
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
# Validates the length of an attribute.
|
199
|
+
def validates_length_of(*atts)
|
200
|
+
opts = {
|
201
|
+
:too_long => 'is too long',
|
202
|
+
:too_short => 'is too short',
|
203
|
+
:wrong_length => 'is the wrong length'
|
204
|
+
}.merge!(atts.extract_options!)
|
205
|
+
|
206
|
+
validates_each(*atts) do |o, a, v|
|
207
|
+
next if (v.nil? && opts[:allow_nil]) || (v.blank? && opts[:allow_blank])
|
208
|
+
if m = opts[:maximum]
|
209
|
+
o.errors[a] << (opts[:message] || opts[:too_long]) unless v && v.size <= m
|
210
|
+
end
|
211
|
+
if m = opts[:minimum]
|
212
|
+
o.errors[a] << (opts[:message] || opts[:too_short]) unless v && v.size >= m
|
213
|
+
end
|
214
|
+
if i = opts[:is]
|
215
|
+
o.errors[a] << (opts[:message] || opts[:wrong_length]) unless v && v.size == i
|
216
|
+
end
|
217
|
+
if w = opts[:within]
|
218
|
+
o.errors[a] << (opts[:message] || opts[:wrong_length]) unless v && w.include?(v.size)
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
NUMBER_RE = /^\d*\.{0,1}\d+$/
|
224
|
+
INTEGER_RE = /\A[+-]?\d+\Z/
|
225
|
+
|
226
|
+
# Validates whether an attribute is a number.
|
227
|
+
def validates_numericality_of(*atts)
|
228
|
+
opts = {
|
229
|
+
:message => 'is not a number',
|
230
|
+
}.merge!(atts.extract_options!)
|
231
|
+
|
232
|
+
re = opts[:only_integer] ? INTEGER_RE : NUMBER_RE
|
233
|
+
|
234
|
+
validates_each(*atts) do |o, a, v|
|
235
|
+
next if (v.nil? && opts[:allow_nil]) || (v.blank? && opts[:allow_blank])
|
236
|
+
o.errors[a] << opts[:message] unless v.to_s =~ re
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
# Validates the presence of an attribute.
|
241
|
+
def validates_presence_of(*atts)
|
242
|
+
opts = {
|
243
|
+
:message => 'is not present',
|
244
|
+
}.merge!(atts.extract_options!)
|
245
|
+
|
246
|
+
validates_each(*atts) do |o, a, v|
|
247
|
+
o.errors[a] << opts[:message] unless v && !v.blank?
|
248
|
+
end
|
249
|
+
end
|
250
|
+
end
|
251
|
+
end
|
data/lib/rcap/version.rb
CHANGED
data/lib/rcap.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
# System and require libs
|
2
2
|
require 'date'
|
3
|
-
require 'assistance'
|
4
3
|
require 'uuidtools'
|
5
4
|
require 'yaml'
|
6
5
|
require 'json'
|
@@ -10,7 +9,14 @@ require 'open-uri'
|
|
10
9
|
require 'base64'
|
11
10
|
require 'digest/sha1'
|
12
11
|
|
12
|
+
# these files are taken from the defunct assitance gem and are included as source in this gem
|
13
|
+
require 'assistance/extract_options'
|
14
|
+
require 'assistance/validation'
|
15
|
+
|
13
16
|
# Extensions
|
17
|
+
require 'rcap/extensions/nil_class'
|
18
|
+
require 'rcap/extensions/fixnum'
|
19
|
+
require 'rcap/extensions/float'
|
14
20
|
require 'rcap/extensions/array'
|
15
21
|
require 'rcap/extensions/string'
|
16
22
|
require 'rcap/extensions/date_time'
|
data/rcap.gemspec
CHANGED
data/spec/alert_spec.rb
CHANGED
@@ -257,7 +257,7 @@ describe( RCAP::Alert ) do
|
|
257
257
|
|
258
258
|
@alert.infos.size.should == 2
|
259
259
|
info = @alert.infos.first
|
260
|
-
info.categories.include?( RCAP::CAP_1_1::Info::CATEGORY_GEO ).should
|
260
|
+
info.categories.include?( RCAP::CAP_1_1::Info::CATEGORY_GEO ).should eq true
|
261
261
|
|
262
262
|
info.areas.size.should == 1
|
263
263
|
area = info.areas.first
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rcap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Farrel Lifson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: assistance
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 0.1.5
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 0.1.5
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: json
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -109,6 +95,8 @@ files:
|
|
109
95
|
- Gemfile
|
110
96
|
- README.md
|
111
97
|
- Rakefile
|
98
|
+
- lib/assistance/extract_options.rb
|
99
|
+
- lib/assistance/validation.rb
|
112
100
|
- lib/rcap.rb
|
113
101
|
- lib/rcap/alert.rb
|
114
102
|
- lib/rcap/base/alert.rb
|
@@ -155,6 +143,9 @@ files:
|
|
155
143
|
- lib/rcap/extensions/array.rb
|
156
144
|
- lib/rcap/extensions/date.rb
|
157
145
|
- lib/rcap/extensions/date_time.rb
|
146
|
+
- lib/rcap/extensions/fixnum.rb
|
147
|
+
- lib/rcap/extensions/float.rb
|
148
|
+
- lib/rcap/extensions/nil_class.rb
|
158
149
|
- lib/rcap/extensions/string.rb
|
159
150
|
- lib/rcap/extensions/time.rb
|
160
151
|
- lib/rcap/info.rb
|