Class: SpreeProductTranslation::Engine

Inherits:
Rails::Engine
  • Object
show all
Defined in:
lib/spree_product_translation/engine.rb

Class Method Summary collapse

Class Method Details

.activateObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/spree_product_translation/engine.rb', line 14

def self.activate
  Dir.glob(File.join(File.dirname(__FILE__), "../../app/**/*_decorator*.rb")) do |c|
    Rails.application.config.cache_classes ? require(c) : load(c)
  end

  Dir.glob(File.join(File.dirname(__FILE__), "../../app/overrides/*.rb")) do |c|
    Rails.application.config.cache_classes ? require(c) : load(c)
  end
  
  ::Product.class_eval do
    translates :name, :description, :meta_description, :meta_keywords, :copy => true

    accepts_nested_attributes_for :translations
  end
  
  ::ProductProperty.class_eval do
    translates :value, :copy => true

    accepts_nested_attributes_for :translations, :reject_if => proc { |attributes| attributes['value'].blank? }
    validates_presence_of :value
  end
  
  ::Property.class_eval do
    translates :presentation

    accepts_nested_attributes_for :translations
  end
  
  ::Prototype.class_eval do
    translates :name, :copy => true

    accepts_nested_attributes_for :translations
  end
  
  ::Taxonomy.class_eval do
    translates :name, :copy => true

    accepts_nested_attributes_for :translations
  end
  
  
  ::Taxon.class_eval do
    translates :name, :description, :copy => true
    
    accepts_nested_attributes_for :translations
  end

  ::OptionType.class_eval do
    translates :presentation
    
    accepts_nested_attributes_for :translations, :reject_if => proc { |attributes| attributes['presentation'].blank? }
    accepts_nested_attributes_for :option_values, :allow_destroy => true
  end

  ::OptionValue.class_eval do
    translates :presentation
    
    accepts_nested_attributes_for :translations, :reject_if => proc { |attributes| attributes['presentation'].blank? }
    validates_presence_of :name
  end
  
  # Enable I18n fallbacks
  require 'i18n/backend/fallbacks'
  
end