Class: Avrodrome::Registry
- Inherits:
-
Object
- Object
- Avrodrome::Registry
- Defined in:
- lib/avrodrome/registry.rb
Instance Method Summary collapse
- #find(id) ⇒ Object
- #next_id ⇒ Object
- #register!(subject_name, schema) ⇒ Object
- #schemas ⇒ Object
- #subject(name) ⇒ Object
- #subjects ⇒ Object
Instance Method Details
#find(id) ⇒ Object
17 18 19 |
# File 'lib/avrodrome/registry.rb', line 17 def find(id) schemas.detect {|x| x.id == id } end |
#next_id ⇒ Object
25 26 27 |
# File 'lib/avrodrome/registry.rb', line 25 def next_id (subjects.sum(&:total_schemas) || 0) + 1 end |
#register!(subject_name, schema) ⇒ Object
12 13 14 15 |
# File 'lib/avrodrome/registry.rb', line 12 def register!(subject_name, schema) subject = subjects.detect {|x| x.name == subject_name } || (Avrodrome::Subject.new(name: subject_name).tap { |x| subjects << x } ) subject.register!(schema: schema, id: next_id) end |
#schemas ⇒ Object
8 9 10 |
# File 'lib/avrodrome/registry.rb', line 8 def schemas subjects.map(&:schemas).flatten end |
#subject(name) ⇒ Object
21 22 23 |
# File 'lib/avrodrome/registry.rb', line 21 def subject(name) subjects.detect {|x| x.name == name } end |
#subjects ⇒ Object
4 5 6 |
# File 'lib/avrodrome/registry.rb', line 4 def subjects @subjects ||= [] end |