1- if RUBY_VERSION >= "1.9"
2- require 'csv'
3- end
1+ require 'csv'
2+
43begin
5- # require 'active_support'
64 require 'active_support/core_ext/object/blank'
75 require 'active_support/inflector'
86 require 'active_support/core_ext/string/inflections'
@@ -63,11 +61,7 @@ def self.morph_attributes klass
6361 end
6462
6563 def self . morph_methods klass
66- methods = if RUBY_VERSION >= "1.9"
67- @morph_methods [ klass ] . keys . sort
68- else
69- @morph_methods [ klass ] . keys . map ( &:to_s ) . sort
70- end
64+ methods = @morph_methods [ klass ] . keys . sort
7165
7266 if klass . superclass . respond_to? ( :morph_attributes )
7367 methods += klass . superclass . morph_methods
@@ -97,9 +91,7 @@ def self.add_morph_attribute klass, attribute
9791
9892 def self . morph_method_missing object , symbol , *args
9993 attribute = symbol . to_s . chomp '='
100- if RUBY_VERSION >= "1.9"
101- attribute = attribute . to_sym
102- end
94+ attribute = attribute . to_sym
10395
10496 if Object . instance_methods . include? ( attribute )
10597 raise "'#{ attribute } ' is an instance_method on Object, cannot create accessor methods for '#{ attribute } '"
@@ -132,7 +124,7 @@ def self.convert_to_morph_method_name label
132124end
133125
134126module Morph
135- VERSION = '0.5.1 ' unless defined? Morph ::VERSION
127+ VERSION = '0.6.0 ' unless defined? Morph ::VERSION
136128
137129 class << self
138130 def classes
@@ -157,23 +149,13 @@ def generate_migrations object, options={}
157149
158150 def from_csv csv , class_name , namespace = Morph
159151 objects = [ ]
160- if !( RUBY_VERSION >= "1.9" )
161- begin
162- require 'fastercsv'
163- rescue LoadError
164- puts "\n You need to install the fastercsv gem to use Morph.from_csv() with Ruby 1.8"
165- puts " gem install fastercsv\n "
152+ CSV . parse ( csv , { :headers => true } ) do |row |
153+ object = object_from_name class_name , namespace
154+ row . each do |key , value |
155+ object . morph ( key , value )
166156 end
157+ objects << object
167158 end
168-
169- csv_utility = ( RUBY_VERSION >= "1.9" ) ? CSV : 'FasterCSV' . constantize
170- csv_utility . parse ( csv , { :headers => true } ) do |row |
171- object = object_from_name class_name , namespace
172- row . each do |key , value |
173- object . morph ( key , value )
174- end
175- objects << object
176- end
177159 objects
178160 end
179161
0 commit comments