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 record 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.
30 31 32 33 34 |
# File 'lib/kbsecret/record.rb', line 30 def self.class_for(type) klass = record_classes.find { |c| c.type == type.to_sym } raise Exceptions::RecordTypeUnknownError, type unless klass klass 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.
49 50 51 52 53 54 55 |
# File 'lib/kbsecret/record.rb', line 49 def self.load_record!(session, path) hsh = JSON.parse(File.read(path), symbolize_names: true) klass = class_for hsh[:type] klass&.load!(session, hsh) rescue raise Exceptions::RecordLoadError, path end |
.record_classes ⇒ Array<Class>
Returns the class objects of all non-abstract record types.
16 17 18 19 20 |
# File 'lib/kbsecret/record.rb', line 16 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.
23 24 25 |
# File 'lib/kbsecret/record.rb', line 23 def self.record_types record_classes.map(&:type) end |
.type?(type) ⇒ Boolean
Returns whether a record class exists of the given type.
38 39 40 41 |
# File 'lib/kbsecret/record.rb', line 38 def self.type?(type) return false unless type record_types.include?(type.to_sym) end |