Class: DhEasy::Router::Seeder

Inherits:
Object
  • Object
show all
Includes:
Plugin::Router
Defined in:
lib/dh_easy/router/seeder.rb

Overview

Seeder router designed to execute all seeders classes.

Instance Attribute Summary

Attributes included from Plugin::Router

#local_config

Instance Method Summary collapse

Methods included from Plugin::Router

#class_defined?, #config, #get_class, #initialize, #initialize_hook_router_plugin_router

Instance Method Details

#route(opts = {}) ⇒ Object

Note:

Requires the route class to implement ‘seed` instance method.

Execute the seeder class with options as described by router

configuration and calling class's instance `seed` method.

Parameters:

  • opts (Hash) (defaults to: {})

    ({}) Seeder initializer options (see DhEasy::Core::Plugin::Seeder).

Raises:

  • (ArgumentError)

    opts` is `nil`.

  • (ArgumentError)

    ‘page_type` doesn’t exists within routes.

  • (NameError)

    A class with name equal to route’s ‘class` attribute doesn’t exists.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/dh_easy/router/seeder.rb', line 19

def route opts = {}
  context = opts[:context]
  if opts[:context].nil?
    raise ArgumentError.new('Must send a context to the seeder.')
  end

  class_name = nil
  config['seeder']['routes'].each do |item|
    # Validate class name
    executor_class = get_class item['class']
    if executor_class.nil?
      raise NameError.new("Class \"#{item['class']}\" doesn't exists, check your dh_easy config file.")
    end

    executor_class.new(opts).seed
  end
end