Module: Workbench::InstanceMethods

Defined in:
lib/workbench.rb

Instance Method Summary collapse

Instance Method Details

#assign_model_attributes(model, attributes) ⇒ Object



7
8
9
10
11
# File 'lib/workbench.rb', line 7

def assign_model_attributes(model, attributes)
  attributes.each do |k, v|
    model.send("#{k}=", v)
  end
end

#find_model_by_attributes(klass, attributes) ⇒ Object



21
22
23
# File 'lib/workbench.rb', line 21

def find_model_by_attributes(klass, attributes)
  klass.where(attributes).first
end

#new_model(klass) ⇒ Object



25
26
27
# File 'lib/workbench.rb', line 25

def new_model(klass)
  klass.new
end

#save_model(model) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/workbench.rb', line 13

def save_model(model)
  if model.respond_to?(:save!) # save should raise if unsuccessful
    model.save!
  else
    model.save
  end
end