Module: CanTango::Registry::Hash::InstanceMethods
- Included in:
- Config::Engines, CanTango::Registry::Hash
- Defined in:
- lib/cantango/registry/hash.rb
Instance Method Summary collapse
- #<<(hash) ⇒ Object
- #[](label) ⇒ Object
- #[]=(label, value) ⇒ Object
- #clean! ⇒ Object (also: #clear!)
- #default ⇒ Object
- #default! ⇒ Object
- #default=(hash) ⇒ Object
- #register(hash) ⇒ Object
- #registered ⇒ Object
- #registered?(label) ⇒ Boolean (also: #registered_name)
- #registered_names ⇒ Object
- #registered_value?(value) ⇒ Boolean
- #registered_values ⇒ Object
- #types ⇒ Object
- #types=(*types) ⇒ Object
- #unregister(name) ⇒ Object
- #value_methods ⇒ Object
- #value_types ⇒ Object
Instance Method Details
#<<(hash) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/cantango/registry/hash.rb', line 30 def << hash raise "Must be a Hash" if !hash? hash registered.merge!(hash) and return if value_methods.empty? && value_types.empty? hash.each_pair do |key, value| registered[key] = value if value_api.all?{|m| value.respond_to(m)} && value.any_kind_of?(value_types) end end |
#[](label) ⇒ Object
38 39 40 41 |
# File 'lib/cantango/registry/hash.rb', line 38 def [] label raise "Must be a label" if !label.kind_of_label? registered[label.to_s] end |
#[]=(label, value) ⇒ Object
43 44 45 46 |
# File 'lib/cantango/registry/hash.rb', line 43 def []= label, value raise "Must be a label" if !label.kind_of_label? registered[label.to_s] = value end |
#clean! ⇒ Object Also known as: clear!
21 22 23 |
# File 'lib/cantango/registry/hash.rb', line 21 def clean! registered = Hashie::Mash.new end |
#default ⇒ Object
79 80 81 |
# File 'lib/cantango/registry/hash.rb', line 79 def default @default ||= Hashie::Mash.new end |
#default! ⇒ Object
26 27 28 |
# File 'lib/cantango/registry/hash.rb', line 26 def default! @registered = default end |
#default=(hash) ⇒ Object
83 84 85 |
# File 'lib/cantango/registry/hash.rb', line 83 def default= hash @default = Hashie::Mash.new hash end |
#register(hash) ⇒ Object
48 49 50 51 |
# File 'lib/cantango/registry/hash.rb', line 48 def register hash raise "Must be a hash" if !hash? hash registered.merge! hash end |
#registered ⇒ Object
58 59 60 |
# File 'lib/cantango/registry/hash.rb', line 58 def registered @registered ||= default end |
#registered?(label) ⇒ Boolean Also known as: registered_name
70 71 72 |
# File 'lib/cantango/registry/hash.rb', line 70 def registered? label registered_names.map(&:to_s).include? label.to_s end |
#registered_names ⇒ Object
62 63 64 |
# File 'lib/cantango/registry/hash.rb', line 62 def registered_names registered.keys end |
#registered_value?(value) ⇒ Boolean
75 76 77 |
# File 'lib/cantango/registry/hash.rb', line 75 def registered_value? value registered_values.include? value end |
#registered_values ⇒ Object
66 67 68 |
# File 'lib/cantango/registry/hash.rb', line 66 def registered_values registered.values end |
#types ⇒ Object
9 10 11 |
# File 'lib/cantango/registry/hash.rb', line 9 def types [::Hash] end |
#types=(*types) ⇒ Object
5 6 7 |
# File 'lib/cantango/registry/hash.rb', line 5 def types= *types raise "This is a Hash registry!" end |
#unregister(name) ⇒ Object
53 54 55 56 |
# File 'lib/cantango/registry/hash.rb', line 53 def unregister name @registered = {} if name == :all @registered.delete(name) end |
#value_methods ⇒ Object
13 14 15 |
# File 'lib/cantango/registry/hash.rb', line 13 def value_methods [] end |
#value_types ⇒ Object
17 18 19 |
# File 'lib/cantango/registry/hash.rb', line 17 def value_types [] end |