Class: CanTango::Configuration::Registry::Hash

Inherits:
Base
  • Object
show all
Defined in:
lib/cantango/configuration/registry/hash.rb

Direct Known Subclasses

Categories, Engines, Hooks

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

#defaultObject



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

#registeredObject



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

Returns:

  • (Boolean)


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_namesObject



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

def registered_names
  registered.keys
end

#registered_value?(value) ⇒ Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/cantango/configuration/registry/hash.rb', line 78

def registered_value? value
  registered_values.include? value
end

#registered_valuesObject



69
70
71
# File 'lib/cantango/configuration/registry/hash.rb', line 69

def registered_values
  registered.values
end

#typesObject



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_methodsObject



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

def value_methods
  []
end

#value_typesObject



20
21
22
# File 'lib/cantango/configuration/registry/hash.rb', line 20

def value_types
  []
end