Module: Sequel::Plugins::Translatable

Defined in:
lib/sequel/plugins/translatable.rb

Defined Under Namespace

Modules: ClassMethods, DatasetMethods, InstanceMethods

Class Method Summary collapse

Class Method Details

.configure(model, attributes = []) ⇒ Object

Raises:

  • (Error)


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/sequel/plugins/translatable.rb', line 4

def self.configure(model, attributes = [])
  attributes = [*attributes]
  raise Error, "please specify attributes to use for translatable plugin" if attributes.empty?
  attributes.each do |attribute|
    model.class_eval "      def \#{attribute}=(value)\n        send \"\#{attribute}_\\\#{base_locale}=\", value\n      end\n      def \#{attribute}\n        send \"\#{attribute}_\\\#{base_locale}\"\n      end\n      def \#{attribute}_hash\n        @\#{attribute}_locales ||= columns.collect do |column|\n          $1 if column=~/\\\\A\#{Regexp.escape attribute}_(.+)\\\\z/\n        end.compact.sort.collect(&:to_sym)\n        hash = {}\n        @\#{attribute}_locales.each do |locale|\n          hash[locale] = send \"\#{attribute}_\\\#{locale}\"\n        end\n        hash\n      end\n    EOS\n  end\nend\n", __FILE__, __LINE__