Module: KBSecret::Record
- Defined in:
- lib/kbsecret/record.rb,
lib/kbsecret/record/todo.rb,
lib/kbsecret/record/login.rb,
lib/kbsecret/record/snippet.rb,
lib/kbsecret/record/abstract.rb,
lib/kbsecret/record/environment.rb,
lib/kbsecret/record/unstructured.rb
Overview
The namespace for kbsecret records types.
Defined Under Namespace
Classes: Abstract, Environment, Login, Snippet, Todo, Unstructured
Class Method Summary collapse
-
.class_for(type) ⇒ Class?
The record class corresponding to the given type.
-
.load_record!(session, path) ⇒ Record::AbstractRecord
private
Load a record by path into the given session.
-
.record_classes ⇒ Array<Class>
The class objects of all non-abstract record types.
-
.record_types ⇒ Array<Symbol>
The types of all records.
-
.type?(type) ⇒ Boolean
Whether a record class exists of the given type.
Class Method Details
.class_for(type) ⇒ Class?
Returns the record class corresponding to the given type.
27 28 29 |
# File 'lib/kbsecret/record.rb', line 27 def self.class_for(type) record_classes.find { |c| c.type == type.to_sym } end |
.load_record!(session, path) ⇒ Record::AbstractRecord
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Load a record by path into the given session.
43 44 45 46 47 |
# File 'lib/kbsecret/record.rb', line 43 def self.load_record!(session, path) hsh = JSON.parse(File.read(path), symbolize_names: true) klass = record_classes.find { |c| c.type == hsh[:type].to_sym } klass&.load!(session, hsh) end |
.record_classes ⇒ Array<Class>
Returns the class objects of all non-abstract record types.
14 15 16 17 18 |
# File 'lib/kbsecret/record.rb', line 14 def self.record_classes klasses = constants.map(&Record.method(:const_get)).grep(Class) klasses.delete(Record::Abstract) klasses end |
.record_types ⇒ Array<Symbol>
Returns the types of all records.
21 22 23 |
# File 'lib/kbsecret/record.rb', line 21 def self.record_types record_classes.map(&:type) end |
.type?(type) ⇒ Boolean
Returns whether a record class exists of the given type.
33 34 35 36 |
# File 'lib/kbsecret/record.rb', line 33 def self.type?(type) return false unless type record_types.include?(type.to_sym) end |