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.
32 33 34 35 36 |
# File 'lib/kbsecret/record.rb', line 32 def 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.
51 52 53 54 55 56 57 |
# File 'lib/kbsecret/record.rb', line 51 def load_record!(session, path) hsh = JSON.parse(File.read(path), symbolize_names: true) klass = class_for hsh[:type] klass.load!(session, hsh) rescue Exceptions::RecordTypeUnknownError, JSON::JSONError raise Exceptions::RecordLoadError, path end |
.record_classes ⇒ Array<Class>
Returns the class objects of all non-abstract record types.
18 19 20 21 22 |
# File 'lib/kbsecret/record.rb', line 18 def 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.
25 26 27 |
# File 'lib/kbsecret/record.rb', line 25 def record_types record_classes.map(&:type) end |
.type?(type) ⇒ Boolean
Returns whether a record class exists of the given type.
40 41 42 43 |
# File 'lib/kbsecret/record.rb', line 40 def type?(type) return false unless type record_types.include?(type.to_sym) end |