Class: Avrodrome::Subject
- Inherits:
-
Object
- Object
- Avrodrome::Subject
- Defined in:
- lib/avrodrome/subject.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #check(schema) ⇒ Object
- #config ⇒ Object
- #find(id) ⇒ Object
-
#initialize(name:) ⇒ Subject
constructor
A new instance of Subject.
- #register!(schema:, id:, version: next_version) ⇒ Object
- #schemas ⇒ Object
- #total_schemas ⇒ Object
- #version(version = nil) ⇒ Object
Constructor Details
#initialize(name:) ⇒ Subject
Returns a new instance of Subject.
5 6 7 |
# File 'lib/avrodrome/subject.rb', line 5 def initialize(name:) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/avrodrome/subject.rb', line 3 def name @name end |
Instance Method Details
#check(schema) ⇒ Object
25 26 27 |
# File 'lib/avrodrome/subject.rb', line 25 def check(schema) schemas.detect {|x| x.body == schema } end |
#config ⇒ Object
9 10 11 |
# File 'lib/avrodrome/subject.rb', line 9 def config @config ||= {} end |
#find(id) ⇒ Object
13 14 15 |
# File 'lib/avrodrome/subject.rb', line 13 def find(id) schemas.detect {|x| x.id == id} end |
#register!(schema:, id:, version: next_version) ⇒ Object
33 34 35 |
# File 'lib/avrodrome/subject.rb', line 33 def register!(schema:, id:, version: next_version) Avrodrome::Schema.new(body: schema, id: id, version: version, name: name).tap { |x| schemas << x } end |
#schemas ⇒ Object
29 30 31 |
# File 'lib/avrodrome/subject.rb', line 29 def schemas @schemas ||= [] end |
#total_schemas ⇒ Object
37 38 39 |
# File 'lib/avrodrome/subject.rb', line 37 def total_schemas schemas.count end |
#version(version = nil) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/avrodrome/subject.rb', line 17 def version(version=nil) if version schemas.detect {|x| x.version == version } else schemas.last end end |