lib/datashift/method_detail.rb in datashift-0.2.2 vs lib/datashift/method_detail.rb in datashift-0.4.0
- old
+ new
@@ -12,53 +12,14 @@
#
require 'to_b'
module DataShift
- # Stores MethodDetails for a class mapped by type
- class MethodDetailsManager
-
- attr_reader :method_details
-
- def initialize( klass )
- @parent_class = klass
- @method_details = {}
- @method_details_list = {}
- end
-
- def add(method_details)
- @method_details[method_details.operator_type] ||= {}
- @method_details_list[method_details.operator_type] ||= []
-
- @method_details[method_details.operator_type][method_details.name] = method_details
- @method_details_list[method_details.operator_type] << method_details
- @method_details_list[method_details.operator_type].uniq!
- end
-
- def <<(method_details)
- add(method_details)
- end
-
- def find(name, type)
- method_details = get(type)
-
- method_details ? method_details[name] : nil
- end
-
- # type is expected to be one of MethodDetail::supportedtype_enum
- def get( type )
- @method_details[type]
- end
-
- def get_list( type )
- @method_details_list[type]
- end
-
- end
-
class MethodDetail
+ include DataShift::Logging
+
def self.supported_types_enum
@type_enum ||= Set[:assignment, :belongs_to, :has_one, :has_many]
@type_enum
end
@@ -147,11 +108,11 @@
#puts "DEBUG : BELONGS_TO : #{@name} : #{operator} - Lookup #{@current_value} in DB"
insistent_belongs_to(record, @current_value)
elsif( operator_for(:has_many) )
- puts "DEBUG : VALUE TYPE [#{value.class.name.include?(operator.classify)}] [#{ModelMapper.class_from_string(value.class.name)}]" unless(value.is_a?(Array))
+ #puts "DEBUG : VALUE TYPE [#{value.class.name.include?(operator.classify)}] [#{ModelMapper.class_from_string(value.class.name)}]" unless(value.is_a?(Array))
# The include? check is best I can come up with right now .. to handle module/namespaces
# TODO - can we determine the real class type of an association
# e.g given a association taxons, which operator.classify gives us Taxon, but actually it's Spree::Taxon
# so how do we get from 'taxons' to Spree::Taxons ? .. check if further info in reflect_on_all_associations
@@ -166,23 +127,23 @@
#puts "DEBUG : HAS_MANY : #{@name} : #{operator}(#{operator_class}) - Lookup #{@current_value} in DB"
if(value.is_a?(operator_class))
record.send(operator + '=', value)
else
- puts "ERROR #{value.class} - Not expected type for has_one #{operator} - cannot assign"
+ logger.error("ERROR #{value.class} - Not expected type for has_one #{operator} - cannot assign")
# TODO - Not expected type - maybe try to look it up somehow ?"
#insistent_has_many(record, @current_value)
end
elsif( operator_for(:assignment) && @col_type )
#puts "DEBUG : COl TYPE defined for #{@name} : #{@assignment} => #{@current_value} #{@col_type.type}"
- #puts "DEBUG : COl TYPE CAST: #{@current_value} => #{@col_type.type_cast( @current_value ).inspect}"
+ # puts "DEBUG : Column [#{@name}] : COl TYPE CAST: #{@current_value} => #{@col_type.type_cast( @current_value ).inspect}"
record.send( operator + '=' , @col_type.type_cast( @current_value ) )
#puts "DEBUG : MethodDetails Assignment RESULT: #{record.send(operator)}"
elsif( operator_for(:assignment) )
- #puts "DEBUG : Brute force assignment of value #{@current_value} supplied for Column [#{@name}]"
+ #puts "DEBUG : Column [#{@name}] : Brute force assignment of value #{@current_value}"
# brute force case for assignments without a column type (which enables us to do correct type_cast)
# so in this case, attempt straightforward assignment then if that fails, basic ops such as to_s, to_i, to_f etc
insistent_assignment(record, @current_value)
else
puts "WARNING: No operator found for assignment on #{self.inspect} for Column [#{@name}]"
\ No newline at end of file