Class: SeedHelper

Inherits:
Object
  • Object
show all
Extended by:
OutputFormatter, RakeHelper
Defined in:
lib/seed_helper.rb,
lib/seed_helper/version.rb

Defined Under Namespace

Modules: OutputFormatter, RakeHelper

Constant Summary collapse

VERSION =
"1.1.0"

Instance Method Summary collapse

Methods included from OutputFormatter

error, message, output, resource_already_exists, special_message, success

Methods included from RakeHelper

create_seed_task

Instance Method Details

#create_resource(resource_class, attributes) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/seed_helper.rb', line 10

def create_resource(resource_class, attributes)
  if resource = find_resource(resource_class, attributes)
    resource_already_exists(resource)
  else
    resource = resource_class.new(attributes)
    if resource.save
      message = "#{resource} successfully created"
      success(message)
    else
      message = "#{resource} failed to create. Errors: #{resource.errors.full_messages}"
      error(message)
    end
  end
  return resource
end