Class: JsonStatham::Parser
- Inherits:
-
Object
- Object
- JsonStatham::Parser
- Defined in:
- lib/json_statham/parser.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#observer ⇒ Object
readonly
Returns the value of attribute observer.
-
#reader ⇒ Object
readonly
Returns the value of attribute reader.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
- #current_schema ⇒ Object
-
#initialize(name, &block) ⇒ Parser
constructor
A new instance of Parser.
- #previous_duration ⇒ Object
- #reader? ⇒ Boolean
- #schema ⇒ Object
- #store_current_schema ⇒ Object
- #stored_schema ⇒ Object
- #stored_schema? ⇒ Boolean
- #valid? ⇒ Boolean
Constructor Details
#initialize(name, &block) ⇒ Parser
Returns a new instance of Parser.
11 12 13 14 15 16 |
# File 'lib/json_statham/parser.rb', line 11 def initialize(name, &block) Validation.check_object_class(name, [String]) @name = name @block = block end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
5 6 7 |
# File 'lib/json_statham/parser.rb', line 5 def block @block end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/json_statham/parser.rb', line 5 def name @name end |
#observer ⇒ Object (readonly)
Returns the value of attribute observer.
5 6 7 |
# File 'lib/json_statham/parser.rb', line 5 def observer @observer end |
#reader ⇒ Object (readonly)
Returns the value of attribute reader.
5 6 7 |
# File 'lib/json_statham/parser.rb', line 5 def reader @reader end |
Class Method Details
.call(name, &block) ⇒ Object
7 8 9 |
# File 'lib/json_statham/parser.rb', line 7 def self.call(name, &block) new(name, &block).call end |
Instance Method Details
#call ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/json_statham/parser.rb', line 18 def call @reader = JsonStatham::Requests::Reader.call(self) @observer = JsonStatham::Requests::Observer.call(self) result = JsonStatham::Result.call(self) store_current_schema result end |
#current_schema ⇒ Object
54 55 56 |
# File 'lib/json_statham/parser.rb', line 54 def current_schema JsonStatham::Schema.call(schema) end |
#previous_duration ⇒ Object
44 45 46 47 48 |
# File 'lib/json_statham/parser.rb', line 44 def previous_duration return unless reader? reader["duration"] end |
#reader? ⇒ Boolean
50 51 52 |
# File 'lib/json_statham/parser.rb', line 50 def reader? !!reader end |
#schema ⇒ Object
34 35 36 |
# File 'lib/json_statham/parser.rb', line 34 def schema observer&.data end |
#store_current_schema ⇒ Object
28 29 30 31 32 |
# File 'lib/json_statham/parser.rb', line 28 def store_current_schema return unless JsonStatham.config.store_schema? JsonStatham::Requests::Writer.call(self) end |
#stored_schema ⇒ Object
38 39 40 41 42 |
# File 'lib/json_statham/parser.rb', line 38 def stored_schema return unless reader? reader["schema"] end |
#stored_schema? ⇒ Boolean
58 59 60 |
# File 'lib/json_statham/parser.rb', line 58 def stored_schema? !!stored_schema end |
#valid? ⇒ Boolean
62 63 64 |
# File 'lib/json_statham/parser.rb', line 62 def valid? !stored_schema? || (stored_schema == current_schema) end |