rest_my_case 1.7.7 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rest_my_case.rb +4 -0
- data/lib/rest_my_case/context/base.rb +2 -0
- data/lib/rest_my_case/context/status/base.rb +27 -0
- data/lib/rest_my_case/context/status/matcher.rb +34 -0
- data/lib/rest_my_case/context/status/status.rb +35 -0
- data/lib/rest_my_case/version.rb +1 -1
- data/lib/rest_my_case/with_status.rb +18 -0
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bdc2ff5446307048245a590af2738b7a9c3dfd0a
|
4
|
+
data.tar.gz: 1f1cd1627ccedba6bc30fbd88ebe4c003b40ec03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5e9cc9a07735380243bdbcfd0286c3195d689b8929cfa8543f7023cbe10d2b01e0b298924af10b52112a5ac18210d4c155116b064ec2254063ea8574552a6c1
|
7
|
+
data.tar.gz: 08822e4218e6f181dac013047c3e1219e0040d6f4d271c1b8a77e3e2fbb98d10867ac5bbb3feebf78ea8a0573cc95966a7e54bce175636fdfb041deaea2b004b
|
data/lib/rest_my_case.rb
CHANGED
@@ -7,6 +7,9 @@ require 'rest_my_case/config/base'
|
|
7
7
|
require 'rest_my_case/config/general'
|
8
8
|
require 'rest_my_case/defense_attorney/base'
|
9
9
|
require 'rest_my_case/context/base'
|
10
|
+
require 'rest_my_case/context/status/matcher'
|
11
|
+
require 'rest_my_case/context/status/status'
|
12
|
+
require 'rest_my_case/context/status/base'
|
10
13
|
require 'rest_my_case/judge/base'
|
11
14
|
require 'rest_my_case/trial/case'
|
12
15
|
require 'rest_my_case/trial/court'
|
@@ -22,6 +25,7 @@ require 'rest_my_case/accusation_attorneys/presence'
|
|
22
25
|
require 'rest_my_case/accusation_attorneys/numericality'
|
23
26
|
|
24
27
|
require 'rest_my_case/base'
|
28
|
+
require 'rest_my_case/with_status'
|
25
29
|
require 'rest_my_case/validator'
|
26
30
|
|
27
31
|
module RestMyCase
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module RestMyCase
|
2
|
+
module Context
|
3
|
+
module Status
|
4
|
+
|
5
|
+
class Base < Context::Base
|
6
|
+
|
7
|
+
def initialize(*args)
|
8
|
+
super(*args)
|
9
|
+
|
10
|
+
@status = ::RestMyCase::Context::Status::Status.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def status
|
14
|
+
@status
|
15
|
+
end
|
16
|
+
|
17
|
+
def status=(val)
|
18
|
+
raise 'status is a reserved keyword which cannot be set'
|
19
|
+
end
|
20
|
+
|
21
|
+
alias :success? :valid?
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module RestMyCase
|
2
|
+
module Context
|
3
|
+
module Status
|
4
|
+
|
5
|
+
class Matcher
|
6
|
+
|
7
|
+
STATUS_SETTER_REGEX = /\A[a-zA-Z](.*)!\z/
|
8
|
+
STATUS_QUESTION_REGEX = /\A[a-zA-Z](.*)\?\z/
|
9
|
+
|
10
|
+
def initialize(text)
|
11
|
+
@text = text
|
12
|
+
end
|
13
|
+
|
14
|
+
def match?
|
15
|
+
match_as_setter? || match_as_question?
|
16
|
+
end
|
17
|
+
|
18
|
+
def match_as_setter?
|
19
|
+
!!(@text =~ STATUS_SETTER_REGEX)
|
20
|
+
end
|
21
|
+
|
22
|
+
def match_as_question?
|
23
|
+
!!(@text =~ STATUS_QUESTION_REGEX)
|
24
|
+
end
|
25
|
+
|
26
|
+
def status
|
27
|
+
@text[0...-1]
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module RestMyCase
|
2
|
+
module Context
|
3
|
+
module Status
|
4
|
+
|
5
|
+
class Status
|
6
|
+
|
7
|
+
attr_reader :current
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@current = 'ok'
|
11
|
+
end
|
12
|
+
|
13
|
+
def method_missing(method, *args, &block)
|
14
|
+
matcher = ::RestMyCase::Context::Status::Matcher.new(method)
|
15
|
+
|
16
|
+
if matcher.match_as_setter?
|
17
|
+
@current = matcher.status
|
18
|
+
elsif matcher.match_as_question?
|
19
|
+
@current == matcher.status
|
20
|
+
else
|
21
|
+
super
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def respond_to?(method, _include_all = false)
|
26
|
+
matcher = ::RestMyCase::Context::Status::Matcher.new(method)
|
27
|
+
|
28
|
+
matcher.match? || super
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/rest_my_case/version.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
module RestMyCase
|
2
|
+
|
3
|
+
class WithStatus < Base
|
4
|
+
|
5
|
+
def self.trial_court
|
6
|
+
@trial_court ||= Trial::Court.new \
|
7
|
+
Judge::Base, DefenseAttorney::Base, Base, Context::Status::Base
|
8
|
+
end
|
9
|
+
|
10
|
+
def failure!(status, message = nil)
|
11
|
+
context.status.send("#{status}!")
|
12
|
+
|
13
|
+
error!(message || status)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rest_my_case
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- goncalvesjoao
|
@@ -125,6 +125,9 @@ files:
|
|
125
125
|
- lib/rest_my_case/config/base.rb
|
126
126
|
- lib/rest_my_case/config/general.rb
|
127
127
|
- lib/rest_my_case/context/base.rb
|
128
|
+
- lib/rest_my_case/context/status/base.rb
|
129
|
+
- lib/rest_my_case/context/status/matcher.rb
|
130
|
+
- lib/rest_my_case/context/status/status.rb
|
128
131
|
- lib/rest_my_case/defense_attorney/base.rb
|
129
132
|
- lib/rest_my_case/errors.rb
|
130
133
|
- lib/rest_my_case/helpers.rb
|
@@ -133,6 +136,7 @@ files:
|
|
133
136
|
- lib/rest_my_case/trial/court.rb
|
134
137
|
- lib/rest_my_case/validator.rb
|
135
138
|
- lib/rest_my_case/version.rb
|
139
|
+
- lib/rest_my_case/with_status.rb
|
136
140
|
- rest_my_case.gemspec
|
137
141
|
- spec/rest_my_case/base_spec.rb
|
138
142
|
- spec/rest_my_case/defense_attorney/base_spec.rb
|