Replicator is a class registry and factory.
-
Add the dependency to your
shard.yml
:dependencies: replicator: github: first-try-software/replicator
-
Run
shards install
require "replicator"
abstract class Starship
extend Replicator::Replicable
end
class Enterprise < Starship
replicates :galaxy
end
class Cerritos < Starship
replicates :galaxy
end
Starship.replicate(:galaxy) # => [#<Enterprise:0x1099ddd60>, #<Cerritos:0x1099ddd70>] : Array(Starship)
Replicator is ready to use in it's current state. The interfaces are unlikey to change. But, there will be new features added per our roadmap:
- Abstract classes can extend Replicator::Replicable to make their descendants "replicable"
- Concrete, "replicable" classes can self register under one or more keys by calling
replicates :symbol
- Multiple concrete, "replicable" classes can self register under the same key by calling
replicates :symbol
- Registered, "replicable" classes can be instantiated using the abstract parent's
.replicate(:symbol)
method - Positional and named arguments may be passed when initializing "replicable" classes
- A "replicable" class may register as the
default_replica
for an extended abstract parent class, and will be instantiated when an unknown key is requested (good for the null object pattern) - A "replicable" class may register as
replicates_all
in which case, it is always instantiated and returned in addition to the classes that match a requested key
- Fork it (https://github.com/first-try-software/replicator/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
- Alan Ridlehoover - co-creator and maintainer
- Fito von Zastrow - co-creator and maintainer