Module: Keytar::ClassMethods
- Defined in:
- lib/keytar.rb
Overview
class methods to be extended
Instance Method Summary collapse
-
#build_key(options = {}) ⇒ Object
Call Keytar.build_key or Foo.build_key with options :base => self.to_s.downcase, :name => method_name, :args => args.
-
#define_keys(*args) ⇒ Object
(also: #define_key)
sets up configuration options for individual keys alows us to define the keys without calling method missing.
-
#key_config(options = {}) ⇒ Object
a way to define class level configurations for keytar using a hash.
Instance Method Details
#build_key(options = {}) ⇒ Object
Call Keytar.build_key or Foo.build_key with options :base => self.to_s.downcase, :name => method_name, :args => args
81 82 83 84 85 |
# File 'lib/keytar.rb', line 81 def build_key( = {}) input = .reverse_merge(key_config) input.delete(:unique) # class methods don't have a unique key Key.build(input) end |
#define_keys(*args) ⇒ Object Also known as: define_key
sets up configuration options for individual keys alows us to define the keys without calling method missing
61 62 63 64 65 66 67 68 69 |
# File 'lib/keytar.rb', line 61 def define_keys(*args) # coherce args into meaningful things names = []; = {}; args.each {|arg| arg.is_a?(Hash) ? = arg : names << arg} names.each do |name| name = name.to_s.gsub(/(^key$|_key$)/, '') Keytar.define_key_class_method_on(self, .merge(:name => name)) Keytar.define_key_instance_method_on(self, .merge(:name => name)) end end |