Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Freeze attributes array #230

Merged
merged 1 commit into from
May 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/mobility/attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def initialize(*attribute_names, method: :accessor, backend: Mobility.default_ba
raise ArgumentError, "method must be one of: reader, writer, accessor" unless %i[reader writer accessor].include?(method)
@method = method
@options = Mobility.default_options.to_h.merge(backend_options)
@names = attribute_names.map(&:to_s)
@names = attribute_names.map(&:to_s).freeze
raise Mobility::BackendRequired, "Backend option required if Mobility.config.default_backend is not set." if backend.nil?
@backend_name = backend
end
Expand Down
6 changes: 3 additions & 3 deletions lib/mobility/backends/sequel/query_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ module Sequel
class QueryMethods < Module
# @param [Array<String>] attributes Translated attributes
def initialize(attributes, _)
@attributes = attributes.map!(&:to_sym)
@attributes = attributes.map(&:to_sym)

attributes.each do |attribute|
@attributes.each do |attribute|
define_method :"first_by_#{attribute}" do |value|
where(attribute.to_sym => value).select_all(model.table_name).first
where(attribute => value).select_all(model.table_name).first
end
end
end
Expand Down