lib/sequel/extensions/seed.rb
##
# Creates a Seed subclass according to the given +block+.
#
# The +env_labels+ lists on which environments the seed should be applicable.
# If the current environment is not applicable, the seed is ignored. On the
# other hand, if it is applicable, it will be listed in Seed.descendants and
# subject to application (if it was not applied yet).
#
# Expected seed call:
#
#   Sequel.seed(:test) do # seed is only applicable to the test environment
#     def run
#       Entity.create attribute: value
#     end
#   end
#
# Wildcard seed:
#
#   Sequel.seed do # seed is applicable to every environment, or no environment
#     def run
#       Entity.create attribute: value
#     end
#   end
#
Creates a Seed subclass according to the given +block+.
The +env_labels+ lists on which environments the seed should be applicable.
If the current environment is not applicable, the seed is ignored. On the
other hand, if it is applicable, it will be listed in Seed.descendants and
subject to application (if it was not applied yet).

Expected seed call.

Sequel.seed(:test) do # seed is only applicable to the test environment
def run
Entity.create attribute: value
end
end

Wildcard seed.

Sequel.seed do # seed is applicable to every environment, or no environment
def run
Entity.create attribute: value
end
end
Creates a Seed subclass according to the given + block + . The + env_labels + lists on which environments the seed should be applicable . If the current environment is not applicable the seed is ignored . On the other hand if it is applicable it will be listed in Seed . descendants and subject to application ( if it was not applied yet ) . Expected seed call . Sequel . seed ( : test ) do # seed is only applicable to the test environment def run Entity . create attribute : value end end Wildcard seed . Sequel . seed do # seed is applicable to every environment or no environment def run Entity . create attribute : value end end
def seed(*env_labels, &block)
      return if env_labels.length > 0 && !env_labels.map(&:to_sym).include?(Seed.environment)
      seed = Class.new(Seed::Base)
      seed.class_eval(&block) if block_given?
      Seed::Base.inherited(seed) unless Seed::Base.descendants.include?(seed)
      seed
    end
def seed ( * env_labels , & block ) return if env_labels . length > 0 && ! env_labels . map ( & :to_sym ) . include? ( Seed . environment ) seed = Class . new ( Seed :: Base ) seed . class_eval ( & block ) if block_given? Seed :: Base . inherited ( seed ) unless Seed :: Base . descendants . include? ( seed ) seed end
Creates a Seed subclass according to the given +block+.
Creates a Seed subclass according to the given + block + .
env_labels
<not_specific>
block
<not_specific>