diff --git a/lib/mobility/backend/active_model/dirty.rb b/lib/mobility/backend/active_model/dirty.rb index d93af10dc..cfec65459 100644 --- a/lib/mobility/backend/active_model/dirty.rb +++ b/lib/mobility/backend/active_model/dirty.rb @@ -23,7 +23,7 @@ module Backend module ActiveModel::Dirty # @!group Backend Accessors # @!macro backend_writer - def write(locale, value, **options) + def write(locale, value, **) locale_accessor = "#{attribute}_#{locale}" if model.changed_attributes.has_key?(locale_accessor) && model.changed_attributes[locale_accessor] == value model.attributes_changed_by_setter.except!(locale_accessor) @@ -43,7 +43,7 @@ def self.included(backend_class) # methods for translated attributes onto model class. module ClassMethods # (see Mobility::Backend::Setup#setup_model) - def setup_model(model_class, attributes, **options) + def setup_model(model_class, attributes, **) super model_class.class_eval do %w[changed? change was will_change! previously_changed? previous_change].each do |suffix| diff --git a/lib/mobility/backend/active_record/hash_valued.rb b/lib/mobility/backend/active_record/hash_valued.rb index 305204d98..7cff2c898 100644 --- a/lib/mobility/backend/active_record/hash_valued.rb +++ b/lib/mobility/backend/active_record/hash_valued.rb @@ -11,12 +11,12 @@ class ActiveRecord::HashValued # @!group Backend Accessors # # @!macro backend_reader - def read(locale, **options) + def read(locale, **) translations[locale] end # @!macro backend_writer - def write(locale, value, **options) + def write(locale, value, **) translations[locale] = value end # @!endgroup diff --git a/lib/mobility/backend/active_record/hstore.rb b/lib/mobility/backend/active_record/hstore.rb index 2d41977f1..7e9716722 100644 --- a/lib/mobility/backend/active_record/hstore.rb +++ b/lib/mobility/backend/active_record/hstore.rb @@ -18,7 +18,7 @@ class ActiveRecord::Hstore < ActiveRecord::HashValued # @!group Backend Accessors # @!macro backend_writer - def write(locale, value, **options) + def write(locale, value, **) translations[locale] = value && value.to_s end # @!endgroup diff --git a/lib/mobility/backend/active_record/hstore/query_methods.rb b/lib/mobility/backend/active_record/hstore/query_methods.rb index 38ee8fab8..9d7f1bf88 100644 --- a/lib/mobility/backend/active_record/hstore/query_methods.rb +++ b/lib/mobility/backend/active_record/hstore/query_methods.rb @@ -1,7 +1,7 @@ module Mobility module Backend class ActiveRecord::Hstore::QueryMethods < ActiveRecord::QueryMethods - def initialize(attributes, **options) + def initialize(attributes, **) super attributes_extractor = @attributes_extractor diff --git a/lib/mobility/backend/active_record/jsonb/query_methods.rb b/lib/mobility/backend/active_record/jsonb/query_methods.rb index b41c2196c..c88ceedef 100644 --- a/lib/mobility/backend/active_record/jsonb/query_methods.rb +++ b/lib/mobility/backend/active_record/jsonb/query_methods.rb @@ -1,7 +1,7 @@ module Mobility module Backend class ActiveRecord::Jsonb::QueryMethods < ActiveRecord::QueryMethods - def initialize(attributes, **options) + def initialize(attributes, **) super attributes_extractor = @attributes_extractor diff --git a/lib/mobility/backend/active_record/key_value.rb b/lib/mobility/backend/active_record/key_value.rb index 5a88fc272..591c0307c 100644 --- a/lib/mobility/backend/active_record/key_value.rb +++ b/lib/mobility/backend/active_record/key_value.rb @@ -28,19 +28,19 @@ class ActiveRecord::KeyValue # @!macro backend_constructor # @option options [Symbol] association_name Name of association - def initialize(model, attribute, **options) + def initialize(model, attribute, **) super @association_name = options[:association_name] end # @!group Backend Accessors # @!macro backend_reader - def read(locale, **options) + def read(locale, **) translation_for(locale).value end # @!macro backend_reader - def write(locale, value, **options) + def write(locale, value, **) translation_for(locale).tap { |t| t.value = value }.value end # @!endgroup diff --git a/lib/mobility/backend/active_record/query_methods.rb b/lib/mobility/backend/active_record/query_methods.rb index fa2282d1d..b6402b0b0 100644 --- a/lib/mobility/backend/active_record/query_methods.rb +++ b/lib/mobility/backend/active_record/query_methods.rb @@ -10,7 +10,7 @@ module ActiveRecord class QueryMethods < Module # @param [Array] attributes Translated attributes # @param [Hash] options Backend options - def initialize(attributes, **options) + def initialize(attributes, **) @attributes = attributes @attributes_extractor = lambda do |opts| opts.is_a?(Hash) && (opts.keys.map(&:to_s) & attributes).presence diff --git a/lib/mobility/backend/active_record/serialized.rb b/lib/mobility/backend/active_record/serialized.rb index 695c9e012..73c2fc252 100644 --- a/lib/mobility/backend/active_record/serialized.rb +++ b/lib/mobility/backend/active_record/serialized.rb @@ -28,12 +28,12 @@ class ActiveRecord::Serialized # @!group Backend Accessors # # @!macro backend_reader - def read(locale, **options) + def read(locale, **) translations[locale] end # @!macro backend_reader - def write(locale, value, **options) + def write(locale, value, **) translations[locale] = value end # @!endgroup diff --git a/lib/mobility/backend/active_record/serialized/query_methods.rb b/lib/mobility/backend/active_record/serialized/query_methods.rb index 368f25784..0410688c4 100644 --- a/lib/mobility/backend/active_record/serialized/query_methods.rb +++ b/lib/mobility/backend/active_record/serialized/query_methods.rb @@ -1,7 +1,7 @@ module Mobility module Backend class ActiveRecord::Serialized::QueryMethods < ActiveRecord::QueryMethods - def initialize(attributes, **options) + def initialize(attributes, **) super attributes_extractor = @attributes_extractor opts_checker = @opts_checker = lambda do |opts| diff --git a/lib/mobility/backend/active_record/table.rb b/lib/mobility/backend/active_record/table.rb index 5097faf6a..fd6200ad3 100644 --- a/lib/mobility/backend/active_record/table.rb +++ b/lib/mobility/backend/active_record/table.rb @@ -82,19 +82,19 @@ class ActiveRecord::Table # @!macro backend_constructor # @option options [Symbol] association_name Name of association - def initialize(model, attribute, **options) + def initialize(model, attribute, **) super @association_name = options[:association_name] end # @!group Backend Accessors # @!macro backend_reader - def read(locale, **options) + def read(locale, **) translation_for(locale).send(attribute) end # @!macro backend_reader - def write(locale, value, **options) + def write(locale, value, **) translation_for(locale).tap { |t| t.send("#{attribute}=", value) }.send(attribute) end # @!endgroup diff --git a/lib/mobility/backend/cache.rb b/lib/mobility/backend/cache.rb index bc946cc77..445d2695a 100644 --- a/lib/mobility/backend/cache.rb +++ b/lib/mobility/backend/cache.rb @@ -35,7 +35,7 @@ module Backend module Cache # @group Backend Accessors # @!macro backend_reader - def read(locale, **options) + def read(locale, **) if write_to_cache? || cache.has_key?(locale) cache[locale] else @@ -44,7 +44,7 @@ def read(locale, **options) end # @!macro backend_writer - def write(locale, value, **options) + def write(locale, value, **) cache[locale] = write_to_cache? ? value : super end # @!endgroup @@ -57,7 +57,7 @@ module Setup # @param model_class Model class # @param [Array] attributes Backend attributes # @param [Hash] options Backend options - def setup_model(model_class, attributes, **options) + def setup_model(model_class, attributes, **) super model_class.include BackendResetter.for(model_class).new(attributes) { clear_cache } end diff --git a/lib/mobility/backend/column.rb b/lib/mobility/backend/column.rb index a82ca08e8..e08750266 100644 --- a/lib/mobility/backend/column.rb +++ b/lib/mobility/backend/column.rb @@ -22,12 +22,12 @@ module Column # @!group Backend Accessors # # @!macro backend_reader - def read(locale, **options) + def read(locale, **) model.send(column(locale)) end # @!macro backend_writer - def write(locale, value, **options) + def write(locale, value, **) model.send("#{column(locale)}=", value) end # @!endgroup diff --git a/lib/mobility/backend/sequel/column/query_methods.rb b/lib/mobility/backend/sequel/column/query_methods.rb index a2ba569d1..27e7599a6 100644 --- a/lib/mobility/backend/sequel/column/query_methods.rb +++ b/lib/mobility/backend/sequel/column/query_methods.rb @@ -1,7 +1,7 @@ module Mobility module Backend class Sequel::Column::QueryMethods < Backend::Sequel::QueryMethods - def initialize(attributes, **options) + def initialize(attributes, **) super attributes_extractor = @attributes_extractor diff --git a/lib/mobility/backend/sequel/dirty.rb b/lib/mobility/backend/sequel/dirty.rb index 7b8e60009..1d55c09f6 100644 --- a/lib/mobility/backend/sequel/dirty.rb +++ b/lib/mobility/backend/sequel/dirty.rb @@ -10,7 +10,7 @@ module Backend module Sequel::Dirty # @!group Backend Accessors # @!macro backend_writer - def write(locale, value, **options) + def write(locale, value, **) locale_accessor = "#{attribute}_#{locale}".to_sym if model.column_changes.has_key?(locale_accessor) && model.initial_values[locale_accessor] == value super @@ -31,7 +31,7 @@ def self.included(backend_class) # methods for translated attributes onto model class. module ClassMethods # (see Mobility::Backend::Setup#setup_model) - def setup_model(model_class, attributes, **options) + def setup_model(model_class, attributes, **) super model_class.class_eval do mod = Module.new do diff --git a/lib/mobility/backend/sequel/hash_valued.rb b/lib/mobility/backend/sequel/hash_valued.rb index 5826c7256..36279d87e 100644 --- a/lib/mobility/backend/sequel/hash_valued.rb +++ b/lib/mobility/backend/sequel/hash_valued.rb @@ -9,12 +9,12 @@ class Sequel::HashValued include Backend # @!macro backend_reader - def read(locale, **options) + def read(locale, **) translations[locale.to_s] end # @!macro backend_writer - def write(locale, value, **options) + def write(locale, value, **) translations[locale.to_s] = value end diff --git a/lib/mobility/backend/sequel/hstore.rb b/lib/mobility/backend/sequel/hstore.rb index 22db755f6..5a1e7cbb3 100644 --- a/lib/mobility/backend/sequel/hstore.rb +++ b/lib/mobility/backend/sequel/hstore.rb @@ -18,7 +18,7 @@ class Sequel::Hstore < Sequel::HashValued # @!group Backend Accessors # @!macro backend_writer - def write(locale, value, **options) + def write(locale, value, **) translations[locale.to_s] = value && value.to_s end # @!endgroup diff --git a/lib/mobility/backend/sequel/hstore/query_methods.rb b/lib/mobility/backend/sequel/hstore/query_methods.rb index 5d2e83aa5..7b4a68696 100644 --- a/lib/mobility/backend/sequel/hstore/query_methods.rb +++ b/lib/mobility/backend/sequel/hstore/query_methods.rb @@ -3,7 +3,7 @@ module Mobility module Backend class Sequel::Hstore::QueryMethods < Sequel::QueryMethods - def initialize(attributes, **options) + def initialize(attributes, **) super attributes_extractor = @attributes_extractor diff --git a/lib/mobility/backend/sequel/jsonb/query_methods.rb b/lib/mobility/backend/sequel/jsonb/query_methods.rb index b3ea9faa2..e14bc7abd 100644 --- a/lib/mobility/backend/sequel/jsonb/query_methods.rb +++ b/lib/mobility/backend/sequel/jsonb/query_methods.rb @@ -3,7 +3,7 @@ module Mobility module Backend class Sequel::Jsonb::QueryMethods < Sequel::QueryMethods - def initialize(attributes, **options) + def initialize(attributes, **) super attributes_extractor = @attributes_extractor diff --git a/lib/mobility/backend/sequel/key_value.rb b/lib/mobility/backend/sequel/key_value.rb index b8337de09..a9b95772d 100644 --- a/lib/mobility/backend/sequel/key_value.rb +++ b/lib/mobility/backend/sequel/key_value.rb @@ -31,12 +31,12 @@ def initialize(model, attribute, **options) # @!group Backend Accessors # @!macro backend_reader - def read(locale, **options) + def read(locale, **) translation_for(locale).value end # @!macro backend_writer - def write(locale, value, **options) + def write(locale, value, **) translation_for(locale).tap { |t| t.value = value }.value end # @!endgroup diff --git a/lib/mobility/backend/sequel/query_methods.rb b/lib/mobility/backend/sequel/query_methods.rb index 245eb865d..c29064bfc 100644 --- a/lib/mobility/backend/sequel/query_methods.rb +++ b/lib/mobility/backend/sequel/query_methods.rb @@ -10,7 +10,7 @@ module Sequel class QueryMethods < Module # @param [Array] attributes Translated attributes # @param [Hash] options Backend options - def initialize(attributes, **options) + def initialize(attributes, **) @attributes = attributes.map! &:to_sym @attributes_extractor = lambda do |cond| cond.is_a?(Hash) && (cond.keys & attributes).presence diff --git a/lib/mobility/backend/sequel/serialized.rb b/lib/mobility/backend/sequel/serialized.rb index 9bbb5515d..ff3f89fdc 100644 --- a/lib/mobility/backend/sequel/serialized.rb +++ b/lib/mobility/backend/sequel/serialized.rb @@ -35,12 +35,12 @@ class Sequel::Serialized # @!group Backend Accessors # # @!macro backend_reader - def read(locale, **options) + def read(locale, **) translations[locale] end # @!macro backend_reader - def write(locale, value, **options) + def write(locale, value, **) translations[locale] = value end # @!endgroup diff --git a/lib/mobility/backend/sequel/serialized/query_methods.rb b/lib/mobility/backend/sequel/serialized/query_methods.rb index 48362525d..88c8f7fdf 100644 --- a/lib/mobility/backend/sequel/serialized/query_methods.rb +++ b/lib/mobility/backend/sequel/serialized/query_methods.rb @@ -1,7 +1,7 @@ module Mobility module Backend class Sequel::Serialized::QueryMethods < Sequel::QueryMethods - def initialize(attributes, **options) + def initialize(attributes, **) super attributes_extractor = @attributes_extractor cond_checker = @cond_checker = lambda do |cond| diff --git a/lib/mobility/backend/sequel/table.rb b/lib/mobility/backend/sequel/table.rb index 89d78850b..d7c59bcdb 100644 --- a/lib/mobility/backend/sequel/table.rb +++ b/lib/mobility/backend/sequel/table.rb @@ -15,19 +15,19 @@ class Sequel::Table # @!macro backend_constructor # @option options [Symbol] association_name Name of association - def initialize(model, attribute, **options) + def initialize(model, attribute, **) super @association_name = options[:association_name] end # @!group Backend Accessors # @!macro backend_reader - def read(locale, **options) + def read(locale, **) translation_for(locale).send(attribute) end # @!macro backend_reader - def write(locale, value, **options) + def write(locale, value, **) translation_for(locale).tap { |t| t.send("#{attribute}=", value) }.send(attribute) end diff --git a/spec/support/shared_examples/accessor_examples.rb b/spec/support/shared_examples/accessor_examples.rb index 77a13a891..831575757 100644 --- a/spec/support/shared_examples/accessor_examples.rb +++ b/spec/support/shared_examples/accessor_examples.rb @@ -36,7 +36,10 @@ Mobility.with_locale(:ja) do expect(instance.public_send(attribute1)).to eq("あああ") expect(instance.public_send(attribute2)).to eq(nil) + expect(instance.public_send(attribute1, { locale: :en })).to eq("foo") + expect(instance.public_send(attribute2, { locale: :en })).to eq("bar") end + expect(instance.public_send(attribute1, { locale: :ja })).to eq("あああ") end instance.save