-
Notifications
You must be signed in to change notification settings - Fork 82
/
hstore.rb
36 lines (29 loc) · 899 Bytes
/
hstore.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
require 'mobility/backend/sequel/hash_valued'
module Mobility
module Backend
=begin
Implements the {Mobility::Backend::Hstore} backend for Sequel models.
@see Mobility::Backend::Sequel::HashValued
=end
class Sequel::Hstore < Sequel::HashValued
autoload :QueryMethods, 'mobility/backend/sequel/hstore/query_methods'
# @!group Backend Accessors
# @!macro backend_reader
# @!method read(locale, **options)
# @!group Backend Accessors
# @!macro backend_writer
def write(locale, value, **)
translations[locale.to_s] = value && value.to_s
end
# @!endgroup
setup do |attributes, options|
extension = Module.new do
define_method :i18n do
@mobility_scope ||= super().with_extend(QueryMethods.new(attributes, options))
end
end
extend extension
end
end
end
end