Module: Shaf::RegistrableFactory

Included in:
Command::Factory, Generator::Factory, Generator::Migration::Factory
Defined in:
lib/shaf/registrable_factory.rb

Defined Under Namespace

Classes: Entry, NoIdentifiersError, NotFoundError

Instance Method Summary collapse

Instance Method Details

#allObject



49
50
51
# File 'lib/shaf/registrable_factory.rb', line 49

def all
  reg.map(&:clazz)
end

#create(*params, **options) ⇒ Object

Raises:



82
83
84
85
86
87
88
# File 'lib/shaf/registrable_factory.rb', line 82

def create(*params, **options)
  entry = lookup_entry(*params)
  raise NotFoundError.new(%Q(Command '#{ARGV}' is not supported)) unless entry

  args = init_args(entry, params)
  entry.clazz.new(*args, **options)
end

#each(&block) ⇒ Object



53
54
55
56
# File 'lib/shaf/registrable_factory.rb', line 53

def each(&block)
  return all.each unless block_given?
  all.each(&block)
end

#lookup(*str) ⇒ Object



71
72
73
# File 'lib/shaf/registrable_factory.rb', line 71

def lookup(*str)
  lookup_entry(*str)&.clazz
end

#register(clazz) ⇒ Object



62
63
64
# File 'lib/shaf/registrable_factory.rb', line 62

def register(clazz)
  reg << Entry.new(clazz)
end

#sizeObject



58
59
60
# File 'lib/shaf/registrable_factory.rb', line 58

def size
  reg.size
end

#unregister(*str) ⇒ Object



66
67
68
69
# File 'lib/shaf/registrable_factory.rb', line 66

def unregister(*str)
  return if str.empty? || !str.all?
  reg.delete_if { |entry| entry.match? str }
end

#usageObject



75
76
77
78
79
80
# File 'lib/shaf/registrable_factory.rb', line 75

def usage
  reg.compact.map do |entry|
    usage = entry.usage
    usage.respond_to?(:call) ? usage.call : usage
  end
end