Class: CanTango::Configuration::Registry::Hash
- Inherits:
-
Base
- Object
- Base
- CanTango::Configuration::Registry::Hash
show all
- Defined in:
- lib/cantango/configuration/registry/hash.rb
Instance Method Summary
collapse
Instance Method Details
#<<(hash) ⇒ Object
33
34
35
36
37
38
39
|
# File 'lib/cantango/configuration/registry/hash.rb', line 33
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
41
42
43
44
|
# File 'lib/cantango/configuration/registry/hash.rb', line 41
def [] label
raise "Must be a label" if !label.kind_of_label?
registered[label.to_s]
end
|
#[]=(label, value) ⇒ Object
46
47
48
49
|
# File 'lib/cantango/configuration/registry/hash.rb', line 46
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!
24
25
26
|
# File 'lib/cantango/configuration/registry/hash.rb', line 24
def clean!
registered = Hashie::Mash.new
end
|
#default ⇒ Object
82
83
84
|
# File 'lib/cantango/configuration/registry/hash.rb', line 82
def default
@default ||= Hashie::Mash.new
end
|
#default! ⇒ Object
29
30
31
|
# File 'lib/cantango/configuration/registry/hash.rb', line 29
def default!
@registered = default
end
|
#default=(hash) ⇒ Object
86
87
88
|
# File 'lib/cantango/configuration/registry/hash.rb', line 86
def default= hash
@default = Hashie::Mash.new hash
end
|
#register(hash) ⇒ Object
51
52
53
54
|
# File 'lib/cantango/configuration/registry/hash.rb', line 51
def register hash
raise "Must be a hash" if !hash? hash
registered.merge! hash
end
|
#registered ⇒ Object
61
62
63
|
# File 'lib/cantango/configuration/registry/hash.rb', line 61
def registered
@registered ||= default
end
|
#registered?(label) ⇒ Boolean
Also known as:
registered_name
73
74
75
|
# File 'lib/cantango/configuration/registry/hash.rb', line 73
def registered? label
registered_names.map(&:to_s).include? label.to_s
end
|
#registered_names ⇒ Object
65
66
67
|
# File 'lib/cantango/configuration/registry/hash.rb', line 65
def registered_names
registered.keys
end
|
#registered_value?(value) ⇒ Boolean
78
79
80
|
# File 'lib/cantango/configuration/registry/hash.rb', line 78
def registered_value? value
registered_values.include? value
end
|
#registered_values ⇒ Object
69
70
71
|
# File 'lib/cantango/configuration/registry/hash.rb', line 69
def registered_values
registered.values
end
|
#types ⇒ Object
12
13
14
|
# File 'lib/cantango/configuration/registry/hash.rb', line 12
def types
[::Hash]
end
|
#types=(*types) ⇒ Object
8
9
10
|
# File 'lib/cantango/configuration/registry/hash.rb', line 8
def types= *types
raise "This is a Hash registry!"
end
|
#unregister(name) ⇒ Object
56
57
58
59
|
# File 'lib/cantango/configuration/registry/hash.rb', line 56
def unregister name
@registered = {} if name == :all
@registered.delete(name)
end
|
#value_methods ⇒ Object
16
17
18
|
# File 'lib/cantango/configuration/registry/hash.rb', line 16
def value_methods
[]
end
|
#value_types ⇒ Object
20
21
22
|
# File 'lib/cantango/configuration/registry/hash.rb', line 20
def value_types
[]
end
|