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

Allows for methods to be overwritten #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 4 additions & 2 deletions lib/flag_shih_tzu.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Would like to support other database adapters so no more hard dependency on Active Record.
require "flag_shih_tzu/validators"
require "pry"

module FlagShihTzu
# taken from ActiveRecord::ConnectionAdapters::Column
Expand Down Expand Up @@ -29,7 +30,8 @@ def has_flags(*args)
column: DEFAULT_COLUMN_NAME,
flag_query_mode: :in_list, # or :bit_operator
strict: false,
check_for_column: true
check_for_column: true,
allow_overwrite: false
}.update(opts)
if !valid_flag_column_name?(opts[:column])
warn %[FlagShihTzu says: Please use a String to designate column names! I see you here: #{caller.first}]
Expand Down Expand Up @@ -72,7 +74,7 @@ def has_flags(*args)
end
# next if method already defined by flag_shih_tzu
next if flag_mapping[colmn][flag_name] & (1 << (flag_key - 1))
if method_defined?(flag_name)
if method_defined?(flag_name) && !opts[:allow_overwrite]
raise ArgumentError,
%[has_flags: flag name #{flag_name} already defined, please choose different name]
end
Expand Down