strelka 0.5.0.pre.393 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1d2cffaf505aa41496b0ce345534e70d6f4b45a0
4
- data.tar.gz: c922b2aa4deafe3472b9be7d2d960237dc2e2b11
3
+ metadata.gz: e6d4fe519bbd4afaacce50262948b7a079041378
4
+ data.tar.gz: 8c38f999384187837c9b15b9786c60a8099aa4fe
5
5
  SHA512:
6
- metadata.gz: 295a62542aae175dd4c70d425fc70f43d314412db557a01989aa63b015931cdf20cad5793fefd4e15a237f49d0f50a17c95b72b5905f321a260520ba4c13e06f
7
- data.tar.gz: 590d6dfab3b2a652e916b9e78ad497440b5e5de314abbd12b5c289fd917d43a1c9e4b212ec55fdc2d030693ef312ea44d8ce0b530c140ee5c714241388a0ae0d
6
+ metadata.gz: 367d122a8c1ca23bb8e49a172e273a5a2b6baba2f0bdae38f576871649ae76637dcd75cf90d3f926852010058c7fab7b9d4ca081da5e056b5d3d1cf91169ff3c
7
+ data.tar.gz: 7da4ade4e80c6a066e20d20748167f583f2536ae18d078798db28a428742f52c76c57ff527e5dfa400f81a175a3cad9988d96b9658f00c0ff0b74fee54aa051d
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/History.rdoc CHANGED
@@ -1,3 +1,11 @@
1
+ == v0.5.0 [2013-05-17] Michael Granger <ged@FaerieMUD.org>
2
+
3
+ - Add :datetime builtin validator
4
+ - Add builtin validators for various checksums.
5
+ - Wire up custom mediatype handlers to content negotiation. Fixes #5.
6
+ - Bump Pluggability dependency
7
+
8
+
1
9
  == v0.4.0 [2013-03-26] Michael Granger <ged@FaerieMUD.org>
2
10
 
3
11
  - Handle Strelka::App subclass inheritance, add Strelka::App syntactic
data/lib/strelka.rb CHANGED
@@ -27,7 +27,7 @@ module Strelka
27
27
  VERSION = '0.5.0'
28
28
 
29
29
  # Version-control revision constant
30
- REVISION = %q$Revision: 49ae27e4588e $
30
+ REVISION = %q$Revision: 80db7acd42dc $
31
31
 
32
32
  require 'strelka/constants'
33
33
  require 'strelka/exceptions'
@@ -65,6 +65,17 @@ require 'strelka/app' unless defined?( Strelka::App )
65
65
  # end
66
66
  #
67
67
  #
68
+ # == Supported/Planned Options
69
+ #
70
+ # The 'resource' directive accepts options that control which methods it
71
+ # creates for the specified resource:
72
+ #
73
+ # [√] :readonly => false
74
+ # [ ] :include => <array of verbs>
75
+ # [ ] :exclude => <array of verbs>
76
+ # [ ] :subsets => <boolean or array>
77
+ # [ ] :associations => <boolean or array>
78
+ #
68
79
  module Strelka::App::RestResources
69
80
  extend Strelka::Plugin
70
81
 
@@ -203,7 +214,6 @@ module Strelka::App::RestResources
203
214
  attributes.map {|name,type| " "}
204
215
  end
205
216
 
206
-
207
217
  return res
208
218
  end
209
219
 
@@ -427,7 +427,13 @@ class Strelka::ParamValidator
427
427
  :uri => /^(?<uri>#{URI::URI_REF})$/,
428
428
  :uuid => /^(?<uuid>[[:xdigit:]]{8}(?:-[[:xdigit:]]{4}){3}-[[:xdigit:]]{12})$/i,
429
429
  :date => /.*\d.*/,
430
+ :datetime => /.*\d.*/,
430
431
  :json => JSON_VALIDATOR_RE,
432
+ :md5sum => /^(?<md5sum>[[:xdigit:]]{32})$/i,
433
+ :sha1sum => /^(?<sha1sum>[[:xdigit:]]{40})$/i,
434
+ :sha256sum => /^(?<sha256sum>[[:xdigit:]]{64})$/i,
435
+ :sha384sum => /^(?<sha384sum>[[:xdigit:]]{96})$/i,
436
+ :sha512sum => /^(?<sha512sum>[[:xdigit:]]{128})$/i,
431
437
  }
432
438
 
433
439
  # Field values which result in a valid ‘true’ value for :boolean constraints
@@ -517,6 +523,14 @@ class Strelka::ParamValidator
517
523
  end
518
524
 
519
525
 
526
+ ### Constrain a value to a parseable Date
527
+ def post_process_datetime( val )
528
+ return Time.parse( val )
529
+ rescue ArgumentError
530
+ return nil
531
+ end
532
+
533
+
520
534
  ### Constrain a value to a Float
521
535
  def post_process_float( val )
522
536
  return Float( val.to_s )
@@ -360,6 +360,60 @@ describe Strelka::ParamValidator do
360
360
 
361
361
  end # describe "hash parameters"
362
362
 
363
+ describe "merging new parameters" do
364
+
365
+ it "can be merged with another set of parameters" do
366
+ @validator.add( :foo, :integer, :required )
367
+ @validator.validate( {} )
368
+ newval = @validator.merge( 'foo' => '1' )
369
+
370
+ newval.should_not equal( @validator )
371
+
372
+ @validator.should_not be_okay()
373
+ @validator.should have_errors()
374
+ newval.should be_okay()
375
+ newval.should_not have_errors()
376
+
377
+ @validator[:foo].should == nil
378
+ newval[:foo].should == 1
379
+ end
380
+
381
+ it "can have required parameters merged into it after the initial validation" do
382
+ @validator.add( :foo, :integer, :required )
383
+ @validator.validate( {} )
384
+ @validator.merge!( 'foo' => '1' )
385
+
386
+ @validator.should be_okay()
387
+ @validator.should_not have_errors()
388
+
389
+ @validator[:foo].should == 1
390
+ end
391
+
392
+ it "can have optional parameters merged into it after the initial validation" do
393
+ @validator.add( :foom, /^\d+$/ )
394
+ @validator.validate( {} )
395
+ @validator.merge!( 'foom' => '5' )
396
+
397
+ @validator.should be_okay()
398
+ @validator.should_not have_errors()
399
+
400
+ @validator[:foom].should == '5'
401
+ end
402
+
403
+ it "rejects invalid parameters when they're merged after initial validation" do
404
+ @validator.add( :foom, /^\d+$/ )
405
+ @validator.add( :bewm, /^\d+$/ )
406
+ @validator.validate( 'foom' => "1" )
407
+
408
+ @validator.merge!( 'bewm' => 'buckwheat noodles' )
409
+
410
+ @validator.should_not be_okay()
411
+ @validator.should have_errors()
412
+ @validator[:bewm].should == nil
413
+ end
414
+
415
+ end # describe "merging new parameters"
416
+
363
417
  describe "builtin constraint type" do
364
418
 
365
419
  it "treats ArgumentErrors as validation failures" do
@@ -715,6 +769,41 @@ describe Strelka::ParamValidator do
715
769
 
716
770
  end
717
771
 
772
+ describe ":datetime constaints" do
773
+
774
+ before( :each ) do
775
+ @validator.add( :expires, :datetime )
776
+ end
777
+
778
+ it "accepts dates" do
779
+ @validator.validate( 'expires' => '2008-11-18' )
780
+
781
+ @validator.should be_okay()
782
+ @validator.should_not have_errors()
783
+
784
+ @validator[:expires].should == Time.parse( '2008-11-18' )
785
+ end
786
+
787
+ it "accepts a date with a time" do
788
+ @validator.validate( 'expires' => '2008-11-18T12:31:18.818Z' )
789
+
790
+ @validator.should be_okay()
791
+ @validator.should_not have_errors()
792
+
793
+ @validator[:expires].should == Time.parse( '2008-11-18T12:31:18.818Z' )
794
+ end
795
+
796
+ it "rejects non-dates" do
797
+ @validator.validate( 'expires' => 'someday' )
798
+
799
+ @validator.should_not be_okay()
800
+ @validator.should have_errors()
801
+
802
+ @validator[:expires].should be_nil()
803
+ end
804
+
805
+ end
806
+
718
807
  describe ":uri constraints" do
719
808
  VALID_URIS = %w{
720
809
  http://127.0.0.1
@@ -1066,60 +1155,6 @@ describe Strelka::ParamValidator do
1066
1155
 
1067
1156
  end
1068
1157
 
1069
- describe "merging new parameters" do
1070
-
1071
- it "can be merged with another set of parameters" do
1072
- @validator.add( :foo, :integer, :required )
1073
- @validator.validate( {} )
1074
- newval = @validator.merge( 'foo' => '1' )
1075
-
1076
- newval.should_not equal( @validator )
1077
-
1078
- @validator.should_not be_okay()
1079
- @validator.should have_errors()
1080
- newval.should be_okay()
1081
- newval.should_not have_errors()
1082
-
1083
- @validator[:foo].should == nil
1084
- newval[:foo].should == 1
1085
- end
1086
-
1087
- it "can have required parameters merged into it after the initial validation" do
1088
- @validator.add( :foo, :integer, :required )
1089
- @validator.validate( {} )
1090
- @validator.merge!( 'foo' => '1' )
1091
-
1092
- @validator.should be_okay()
1093
- @validator.should_not have_errors()
1094
-
1095
- @validator[:foo].should == 1
1096
- end
1097
-
1098
- it "can have optional parameters merged into it after the initial validation" do
1099
- @validator.add( :foom, /^\d+$/ )
1100
- @validator.validate( {} )
1101
- @validator.merge!( 'foom' => '5' )
1102
-
1103
- @validator.should be_okay()
1104
- @validator.should_not have_errors()
1105
-
1106
- @validator[:foom].should == '5'
1107
- end
1108
-
1109
- it "rejects invalid parameters when they're merged after initial validation" do
1110
- @validator.add( :foom, /^\d+$/ )
1111
- @validator.add( :bewm, /^\d+$/ )
1112
- @validator.validate( 'foom' => "1" )
1113
-
1114
- @validator.merge!( 'bewm' => 'buckwheat noodles' )
1115
-
1116
- @validator.should_not be_okay()
1117
- @validator.should have_errors()
1118
- @validator[:bewm].should == nil
1119
- end
1120
-
1121
- end
1122
-
1123
1158
  describe ":json constraint" do
1124
1159
 
1125
1160
  # Some tests derived from the json-smart feature test matrix by Uriel Chemouni:
@@ -1344,9 +1379,138 @@ describe Strelka::ParamValidator do
1344
1379
  end
1345
1380
  end
1346
1381
 
1382
+ describe ":md5sum constraint" do
1383
+
1384
+ let( :sum ) { Digest::MD5.hexdigest('an api key') }
1385
+
1386
+ it "accepts a 32-character hex string" do
1387
+ @validator.add( :apikey, :md5sum )
1388
+ @validator.validate( 'apikey' => sum )
1389
+
1390
+ @validator.should_not have_errors()
1391
+ @validator.should be_okay()
1392
+
1393
+ @validator[:apikey].should == sum
1394
+ end
1395
+
1396
+ it "rejects anything but a 32-character hex string" do
1397
+ @validator.add( :apikey, :md5sum )
1398
+ @validator.validate( 'apikey' => 'my ponies have WINGS!!!11' )
1399
+
1400
+ @validator.should have_errors()
1401
+ @validator.should_not be_okay()
1402
+
1403
+ @validator[:apikey].should be_nil()
1404
+ end
1405
+
1406
+ end
1407
+
1408
+ describe ":sha1sum constraint" do
1409
+
1410
+ let( :sum ) { Digest::SHA1.hexdigest('an api key') }
1411
+
1412
+ it "accepts a 40-character hex string" do
1413
+ @validator.add( :apikey, :sha1sum )
1414
+ @validator.validate( 'apikey' => sum )
1415
+
1416
+ @validator.should_not have_errors()
1417
+ @validator.should be_okay()
1418
+
1419
+ @validator[:apikey].should == sum
1420
+ end
1421
+
1422
+ it "rejects anything but a 40-character hex string" do
1423
+ @validator.add( :apikey, :sha1sum )
1424
+ @validator.validate( 'apikey' => '084444a9979487f43a238e45afc1ec1277a' )
1425
+
1426
+ @validator.should have_errors()
1427
+ @validator.should_not be_okay()
1428
+
1429
+ @validator[:apikey].should be_nil()
1430
+ end
1431
+
1432
+ end
1433
+
1434
+ describe ":sha256sum constraint" do
1435
+
1436
+ let( :sum ) { Digest::SHA256.hexdigest('an api key') }
1437
+
1438
+ it "accepts a 64-character hex string" do
1439
+ @validator.add( :apikey, :sha256sum )
1440
+ @validator.validate( 'apikey' => sum )
1441
+
1442
+ @validator.should_not have_errors()
1443
+ @validator.should be_okay()
1444
+
1445
+ @validator[:apikey].should == sum
1446
+ end
1447
+
1448
+ it "rejects anything but a 64-character hex string" do
1449
+ @validator.add( :apikey, :sha256sum )
1450
+ @validator.validate( 'apikey' => 'a_key' )
1451
+
1452
+ @validator.should have_errors()
1453
+ @validator.should_not be_okay()
1454
+
1455
+ @validator[:apikey].should be_nil()
1456
+ end
1457
+
1458
+ end
1459
+
1460
+ describe ":sha384sum constraint" do
1461
+
1462
+ let( :sum ) { Digest::SHA384.hexdigest('an api key') }
1463
+
1464
+ it "accepts a 96-character hex string" do
1465
+ @validator.add( :apikey, :sha384sum )
1466
+ @validator.validate( 'apikey' => sum )
1467
+
1468
+ @validator.should_not have_errors()
1469
+ @validator.should be_okay()
1470
+
1471
+ @validator[:apikey].should == sum
1472
+ end
1473
+
1474
+ it "rejects anything but a 96-character hex string" do
1475
+ @validator.add( :apikey, :sha384sum )
1476
+ @validator.validate( 'apikey' => ' ' + sum )
1477
+
1478
+ @validator.should have_errors()
1479
+ @validator.should_not be_okay()
1480
+
1481
+ @validator[:apikey].should be_nil()
1482
+ end
1483
+
1484
+ end
1485
+
1486
+ describe ":sha512sum constraint" do
1487
+
1488
+ let( :sum ) { Digest::SHA512.hexdigest('an api key') }
1489
+
1490
+ it "accepts a 128-character hex string" do
1491
+ @validator.add( :apikey, :sha512sum )
1492
+ @validator.validate( 'apikey' => sum )
1493
+
1494
+ @validator.should_not have_errors()
1495
+ @validator.should be_okay()
1496
+
1497
+ @validator[:apikey].should == sum
1498
+ end
1499
+
1500
+ it "rejects anything but a 128-character hex string" do
1501
+ @validator.add( :apikey, :sha512sum )
1502
+ @validator.validate( 'apikey' => '..,,..' )
1503
+
1504
+ @validator.should have_errors()
1505
+ @validator.should_not be_okay()
1506
+
1507
+ @validator[:apikey].should be_nil()
1508
+ end
1347
1509
 
1510
+ end
1348
1511
 
1349
1512
  end # describe "constraints"
1350
1513
 
1514
+
1351
1515
  end
1352
1516
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strelka
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0.pre.393
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Granger
@@ -30,7 +30,7 @@ cert_chain:
30
30
  6mKCwjpegytE0oifXfF8k75A9105cBnNiMZOe1tXiqYc/exCgWvbggurzDOcRkZu
31
31
  /YSusaiDXHKU2O3Akc3htA==
32
32
  -----END CERTIFICATE-----
33
- date: 2013-05-02 00:00:00.000000000 Z
33
+ date: 2013-05-17 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: configurability
@@ -206,14 +206,14 @@ dependencies:
206
206
  requirements:
207
207
  - - ~>
208
208
  - !ruby/object:Gem::Version
209
- version: '3.10'
209
+ version: '4.0'
210
210
  type: :development
211
211
  prerelease: false
212
212
  version_requirements: !ruby/object:Gem::Requirement
213
213
  requirements:
214
214
  - - ~>
215
215
  - !ruby/object:Gem::Version
216
- version: '3.10'
216
+ version: '4.0'
217
217
  - !ruby/object:Gem::Dependency
218
218
  name: hoe-deveiate
219
219
  requirement: !ruby/object:Gem::Requirement
metadata.gz.sig CHANGED
Binary file