Module: CanTango::Registry::Hash::InstanceMethods

Included in:
Config::Engines, CanTango::Registry::Hash
Defined in:
lib/cantango/registry/hash.rb

Instance Method Summary collapse

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

#defaultObject



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

#registeredObject



58
59
60
# File 'lib/cantango/registry/hash.rb', line 58

def registered
  @registered ||= default
end

#registered?(label) ⇒ Boolean Also known as: registered_name

Returns:

  • (Boolean)


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_namesObject



62
63
64
# File 'lib/cantango/registry/hash.rb', line 62

def registered_names
  registered.keys
end

#registered_value?(value) ⇒ Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/cantango/registry/hash.rb', line 75

def registered_value? value
  registered_values.include? value
end

#registered_valuesObject



66
67
68
# File 'lib/cantango/registry/hash.rb', line 66

def registered_values
  registered.values
end

#typesObject



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_methodsObject



13
14
15
# File 'lib/cantango/registry/hash.rb', line 13

def value_methods
  []
end

#value_typesObject



17
18
19
# File 'lib/cantango/registry/hash.rb', line 17

def value_types
  []
end