Module: Oaken::Seeds

Extended by:
Seeds
Included in:
Seeds
Defined in:
lib/oaken/seeds.rb

Class Method Summary collapse

Class Method Details

.loaderObject



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 => 
 => ::Job | AccountJob
 => ::JobTask | ::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

Returns:

  • (Boolean)


28
# File 'lib/oaken/seeds.rb', line 28

def self.respond_to_missing?(meth, ...) = loader.locate(meth) || super

.sectionObject

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