class Dropkiq::DropMethodInstanceSimulator
Attributes
drop_method[RW]
dropkiq_type[RW]
foreign_table_name[RW]
sample_drop[RW]
Public Class Methods
new(drop_method, sample_drop=nil)
click to toggle source
# File lib/dropkiq/drop_method_instance_simulator.rb, line 6 def initialize(drop_method, sample_drop=nil) self.drop_method = drop_method.to_s self.sample_drop = sample_drop end
Public Instance Methods
classify()
click to toggle source
# File lib/dropkiq/drop_method_instance_simulator.rb, line 11 def classify value = begin sample_drop.try(drop_method) rescue end self.dropkiq_type = ruby_data_type_to_dropkiq_type(value) self.dropkiq_type ||= test_for_relationship(value) self end
Private Instance Methods
ruby_data_type_to_dropkiq_type(value)
click to toggle source
# File lib/dropkiq/drop_method_instance_simulator.rb, line 35 def ruby_data_type_to_dropkiq_type(value) case value when NilClass when TrueClass Dropkiq::BOOLEAN_TYPE when FalseClass Dropkiq::BOOLEAN_TYPE when String Dropkiq::STRING_TYPE when Symbol Dropkiq::STRING_TYPE when Numeric Dropkiq::NUMERIC_TYPE when Date Dropkiq::DATE_TIME_TYPE when Time Dropkiq::DATE_TIME_TYPE when DateTime Dropkiq::DATE_TIME_TYPE else end end
test_for_relationship(value)
click to toggle source
# File lib/dropkiq/drop_method_instance_simulator.rb, line 25 def test_for_relationship(value) if value.is_a?(ActiveRecord::Base) self.foreign_table_name = value.class.table_name return Dropkiq::HAS_ONE_TYPE elsif value.respond_to?(:first) && value.first.is_a?(ActiveRecord::Base) self.foreign_table_name = value.first.class.table_name return Dropkiq::HAS_MANY_TYPE end end