Sha256: 5f9f4fd93ac3a92f1f321b16d73fc3d53c8fc78aef9428b11853986f89f7fdd7

Contents?: true

Size: 739 Bytes

Versions: 12

Compression:

Stored size: 739 Bytes

Contents

class ModelMapper
  
  # Helper to deal with string versions of modules/namespaced classes
  # Find and return the base class from a string.
  # 
  # e.g "Spree::Property" returns the Spree::Property class
  # Raises exception if no such class found
  def self.const_get_from_string(str)
    str.to_s.split('::').inject(Object) do |mod, class_name| 
      mod.const_get(class_name) 
    end 
  end 


  # Similar to const_get_from_string except this version
  # returns nil if no such class found
  # Support modules e.g "Spree::Property"
  # 
  def self.class_from_string( str )
      begin
        ModelMapper::const_get_from_string(str.to_s)  #Kernel.const_get(model)
      rescue NameError => e
       return nil
      end
  end
  
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
datashift-0.15.0 lib/datashift/model_mapper.rb
datashift-0.14.0 lib/datashift/model_mapper.rb
datashift-0.13.0 lib/datashift/model_mapper.rb
datashift-0.12.1 lib/datashift/model_mapper.rb
datashift-0.12.0 lib/datashift/model_mapper.rb
datashift-0.11.1 lib/datashift/model_mapper.rb
datashift-0.11.0 lib/datashift/model_mapper.rb
datashift-0.10.2 lib/datashift/model_mapper.rb
datashift-0.10.1 lib/datashift/model_mapper.rb
datashift-0.10.0 lib/datashift/model_mapper.rb
datashift-0.9.0 lib/datashift/model_mapper.rb
datashift-0.8.0 lib/datashift/model_mapper.rb