Module: CanTango::Registry::Base::InstanceMethods

Included in:
CanTango::Registry::Base
Defined in:
lib/cantango/registry/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#availableObject



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

def available
  []
end

#defaultObject



53
54
55
# File 'lib/cantango/registry/base.rb', line 53

def default
  @default ||= []
end

#registeredObject

Returns the value of attribute registered.



9
10
11
# File 'lib/cantango/registry/base.rb', line 9

def registered
  @registered
end

Instance Method Details

#[](index) ⇒ Object



41
42
43
# File 'lib/cantango/registry/base.rb', line 41

def [] index
  registered[index]
end

#clean!Object Also known as: clear!



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

def clean!
  @registered = []
end

#default!Object



30
31
32
# File 'lib/cantango/registry/base.rb', line 30

def default!
  @registered = default
end

#register(*list) ⇒ Object Also known as: <<



34
35
36
37
# File 'lib/cantango/registry/base.rb', line 34

def register *list
  registered << list.select_kinds_of(*types)
  @registered.flat_uniq!
end

#registered?(label) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/cantango/registry/base.rb', line 49

def registered? label
  registered.map(&:to_s).include? label.to_s
end

#reset!Object



24
25
26
# File 'lib/cantango/registry/base.rb', line 24

def reset!
  @registered = default
end

#typesObject



15
16
17
18
# File 'lib/cantango/registry/base.rb', line 15

def types
  @types ||= [Symbol, String]
  @types
end

#types=(*types) ⇒ Object



11
12
13
# File 'lib/cantango/registry/base.rb', line 11

def types= *types
  @types = types.select {|t| t.is_a?(Class) }
end

#valid?(label) ⇒ Boolean

Returns:

  • (Boolean)


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

def valid? label
  return available.include?(label) if respond_to?(:available) && !available.empty?
  true
end