Module: Keytar
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/keytar.rb
Defined Under Namespace
Modules: ClassMethods Classes: Key
Constant Summary collapse
- DEFAULTS =
{:delimiter => ":", :order => [:shard, :prefix, :base, :name, :unique, :args, :suffix, :version, :v], :pluralize_instances => true, :key_case => :downcase, :unique => :id}
Class Method Summary collapse
- .define_key_class_method_on(base, options = {}) ⇒ Object
- .define_key_instance_method_on(base, options) ⇒ Object
Instance Method Summary collapse
-
#build_key(options = {}) ⇒ Object
build_key method for instances by default class is pluralized to create different key.
Class Method Details
.define_key_class_method_on(base, options = {}) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/keytar.rb', line 41 def self.define_key_class_method_on(base, = {}) (class << base;self ;end).instance_eval do define_method("#{options[:name]}_key") do |*args| build_key(.merge(:args => args)) end end end |
.define_key_instance_method_on(base, options) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/keytar.rb', line 49 def self.define_key_instance_method_on(base, ) base.class_eval do define_method("#{options[:name]}_key") do |*args| build_key(.merge(:args => args)) end end end |
Instance Method Details
#build_key(options = {}) ⇒ Object
build_key method for instances by default class is pluralized to create different key
89 90 91 92 93 94 95 |
# File 'lib/keytar.rb', line 89 def build_key( = {}) .reverse_merge!(self.class.key_config) unique = method([:unique].to_sym).call if respond_to?([:unique].to_sym) [:base] = [:base].to_s.pluralize unless [:pluralize_instances].blank? [:unique] = unique && unique == object_id ? nil : unique Key.build() end |