class Goedel::Statement
Attributes
force_attributes[R]
indent[R]
object[R]
override_attributes[R]
Public Class Methods
new(object, options={})
click to toggle source
# File lib/goedel/statement.rb, line 5 def initialize(object, options={}) @object = object @force_attributes = options[:force_attributes] || [] @override_attributes = options[:override_attributes] || {} @indent = 2 end
Public Instance Methods
generate()
click to toggle source
# File lib/goedel/statement.rb, line 12 def generate output_array = [model_instantiate] model_attributes.each do |prop, val| next unless val output_array << "#{" "*indent}#{attr_line(prop, val)}" end output_array << "#{instance_name}.save" output_array.join("\n") end
Private Instance Methods
attr_line(prop, val)
click to toggle source
# File lib/goedel/statement.rb, line 24 def attr_line(prop, val) Goedel::Line.new(instance_name, prop, val).generate end
class_name()
click to toggle source
# File lib/goedel/statement.rb, line 42 def class_name object.class.to_s end
instance_name()
click to toggle source
# File lib/goedel/statement.rb, line 46 def instance_name "my_#{object.class.to_s.downcase}" end
model_attributes()
click to toggle source
# File lib/goedel/statement.rb, line 28 def model_attributes obj_attr = object.attributes force_attributes.each do |attr| prop = attr.to_s val = object.send(attr) obj_attr[prop] = val end obj_attr.merge(override_attributes) end
model_instantiate()
click to toggle source
# File lib/goedel/statement.rb, line 38 def model_instantiate "#{instance_name} = #{class_name}.new" end