Class: EasyCreds::Templates::Registry
- Inherits:
-
Object
- Object
- EasyCreds::Templates::Registry
- Defined in:
- lib/easy_creds/templates/registry.rb
Constant Summary collapse
- BUNDLED_DIR =
File.('files', __dir__).freeze
Instance Method Summary collapse
- #delete(name) ⇒ Object
-
#initialize(global_dir: nil) ⇒ Registry
constructor
A new instance of Registry.
- #list ⇒ Object
- #load(name) ⇒ Object
- #path_for(name) ⇒ Object
- #user_defined?(name) ⇒ Boolean
Constructor Details
#initialize(global_dir: nil) ⇒ Registry
Returns a new instance of Registry.
8 9 10 |
# File 'lib/easy_creds/templates/registry.rb', line 8 def initialize(global_dir: nil) @global_dir = global_dir end |
Instance Method Details
#delete(name) ⇒ Object
31 32 33 34 35 |
# File 'lib/easy_creds/templates/registry.rb', line 31 def delete(name) raise ArgumentError, "Cannot delete bundled template '#{name}'" unless user_defined?(name) File.delete(user_path(name)) end |
#list ⇒ Object
12 13 14 |
# File 'lib/easy_creds/templates/registry.rb', line 12 def list (bundled_names + user_names).uniq end |
#load(name) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/easy_creds/templates/registry.rb', line 16 def load(name) path = user_path(name) || bundled_path(name) raise ArgumentError, "Template '#{name}' not found" unless path YAML.safe_load_file(path) || {} end |
#path_for(name) ⇒ Object
27 28 29 |
# File 'lib/easy_creds/templates/registry.rb', line 27 def path_for(name) user_path(name) || bundled_path(name) end |
#user_defined?(name) ⇒ Boolean
23 24 25 |
# File 'lib/easy_creds/templates/registry.rb', line 23 def user_defined?(name) user_path(name) ? true : false end |