Module: DataShift::SpreeHelper

Defined in:
lib/datashift_spree.rb,
lib/helpers/spree_helper.rb,
lib/loaders/spree/image_loader.rb,
lib/loaders/spree/product_loader.rb

Defined Under Namespace

Classes: ImageLoader, ProductLoader

Class Method Summary collapse

Class Method Details

.app_rootObject



69
70
71
# File 'lib/helpers/spree_helper.rb', line 69

def self.app_root
  File.join(root, 'app')
end

.gem_nameObject



53
54
55
# File 'lib/datashift_spree.rb', line 53

def self.gem_name
  "datashift_spree"
end

.gem_versionObject



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/datashift_spree.rb', line 41

def self.gem_version
  unless(@gem_version)
    if(File.exists?(File.join(root_path, 'VERSION') ))
      File.read( File.join(root_path, 'VERSION') ).match(/.*(\d+.\d+.\d+)/)
      @gem_version = $1
    else
      @gem_version = '1.0.0'
    end
  end
  @gem_version
end

.get_image_owner(product) ⇒ Object



53
54
55
# File 'lib/helpers/spree_helper.rb', line 53

def self.get_image_owner(product)
  (SpreeHelper::version.to_f > 1) ? product.master : product
end

.get_product_classObject



45
46
47
48
49
50
51
# File 'lib/helpers/spree_helper.rb', line 45

def self.get_product_class
  if(is_namespace_version())
    Object.const_get('Spree').const_get('Product')
  else
    Object.const_get('Product')
  end
end

.get_spree_class(x) ⇒ Object

Helpers so we can cope with both pre 1.0 and post 1.0 versions of Spree in same datashift version



37
38
39
40
41
42
43
# File 'lib/helpers/spree_helper.rb', line 37

def self.get_spree_class(x)
  if(is_namespace_version())    
    ModelMapper::class_from_string("Spree::#{x}")
  else
    ModelMapper::class_from_string(x.to_s)
  end
end

.is_namespace_versionObject



61
62
63
# File 'lib/helpers/spree_helper.rb', line 61

def self.is_namespace_version
  SpreeHelper::version.to_f >= 1
end

.lib_rootObject



65
66
67
# File 'lib/helpers/spree_helper.rb', line 65

def self.lib_root
  File.join(root, 'lib')
end

.library_pathObject



61
62
63
# File 'lib/datashift_spree.rb', line 61

def self.library_path
  File.expand_path("#{File.dirname(__FILE__)}/../lib")
end

.loadObject



73
74
75
76
# File 'lib/helpers/spree_helper.rb', line 73

def self.load()
  require 'spree'
  require 'spree_core'
end

.load_commandsObject

Load all the datashift Thor commands and make them available throughout app



107
108
109
110
111
112
113
114
# File 'lib/datashift_spree.rb', line 107

def self.load_commands()
  base = File.join(library_path, 'thor', '**')
  
  Dir["#{base}/*.thor"].each do |f|
    next unless File.file?(f)
    Thor::Util.load_thorfile(f)
  end
end

.load_tasksObject

Load all the datashift rake tasks and make them available throughout app



97
98
99
100
101
102
# File 'lib/datashift_spree.rb', line 97

def self.load_tasks
  # Long parameter lists so ensure rake -T produces nice wide output
  ENV['RAKE_COLUMNS'] = '180'
  base = File.join(root_path, 'tasks', '**')
  Dir["#{base}/*.rake"].sort.each { |ext| load ext }
end

.require_librariesObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/datashift_spree.rb', line 65

def self.require_libraries
  
  loader_libs = %w{ lib  }

  # Base search paths - these will be searched recursively
  loader_paths = []

  loader_libs.each {|l| loader_paths << File.join(root_path(), l) }

  # Define require search paths, any dir in here will be added to LOAD_PATH

  loader_paths.each do |base|
    $:.unshift base  if File.directory?(base)
    Dir[File.join(base, '**', '**')].each do |p|
      if File.directory? p
        $:.unshift p
      end
    end
  end
  
  require_libs = %w{ loaders helpers }
  require_libs.each do |base|
    Dir[File.join(library_path, base, '**/*.rb')].each do |rb|
      unless File.directory? rb
       # require rb
      end
    end
  end

end

.rootObject



31
32
33
# File 'lib/helpers/spree_helper.rb', line 31

def self.root
  Gem.loaded_specs['spree_core'] ? Gem.loaded_specs['spree_core'].full_gem_path  : ""
end

.root_pathObject



57
58
59
# File 'lib/datashift_spree.rb', line 57

def self.root_path
  File.expand_path("#{File.dirname(__FILE__)}/..")
end

.versionObject



57
58
59
# File 'lib/helpers/spree_helper.rb', line 57

def self.version
  Gem.loaded_specs['spree'] ? Gem.loaded_specs['spree'].version.version : "0.0.0"
end