Module: Oaken::Seeds
Class Method Summary collapse
- .loader ⇒ Object
-
.method_missing(meth) ⇒ Object
Oaken’s auto-registering logic.
- .respond_to_missing?(meth) ⇒ Boolean
-
.section ⇒ Object
Purely for decorative purposes to carve up seed files.
Class Method Details
.loader ⇒ Object
2 |
# File 'lib/oaken/seeds.rb', line 2 def self.loader = Oaken.loader |
.method_missing(meth) ⇒ Object
Oaken’s auto-registering logic.
So when you first call e.g. ‘accounts.create`, we’ll hit ‘method_missing` here and automatically call `register Account, as: :accounts`.
We’ll also match partial and full nested namespaces:
accounts => Account
account_jobs => Account::Job | AccountJob
account_job_tasks => Account::JobTask | Account::Job::Task | AccountJob::Task | AccountJobTask
If you have classes that don’t follow these naming conventions, you must call ‘register` manually.
20 21 22 23 24 25 26 27 |
# File 'lib/oaken/seeds.rb', line 20 def self.method_missing(meth, ...) if type = loader.locate(meth) register type, as: meth public_send(meth, ...) else super end end |
.respond_to_missing?(meth) ⇒ Boolean
28 |
# File 'lib/oaken/seeds.rb', line 28 def self.respond_to_missing?(meth, ...) = loader.locate(meth) || super |
.section ⇒ Object
Purely for decorative purposes to carve up seed files.
‘section` is defined as `def section(*, **) = block_given? && yield`, so you can use all of Ruby’s method signature flexibility to help communicate structure better.
Use positional & keyword arguments, blocks at multiple levels, or a combination.
section :basic
users.create name: "Someone"
section :menus, quicksale: true
section do
# Leave name implicit and carve up visually with the indentation.
section something: :nested
section :another_level do
# We can keep going, but maybe we shouldn't.
end
end
50 |
# File 'lib/oaken/seeds.rb', line 50 def self.section(*, **) = block_given? && yield |