Class: BitmaskEnum::ConflictChecker Private
- Inherits:
-
Object
- Object
- BitmaskEnum::ConflictChecker
- Defined in:
- lib/bitmask_enum/conflict_checker.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Checks for method conflicts on the model
Instance Method Summary collapse
-
#check_class_method!(method_name) ⇒ Object
private
Check if the method name is dangerous or already defined on the class.
-
#check_instance_method!(method_name) ⇒ Object
private
Check if the method name is dangerous or already defined on the instance, or defined by another bitmask enum.
-
#initialize(model, attribute, defined_enum_methods) ⇒ ConflictChecker
constructor
private
A new instance of ConflictChecker.
Constructor Details
#initialize(model, attribute, defined_enum_methods) ⇒ ConflictChecker
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of ConflictChecker.
9 10 11 12 13 |
# File 'lib/bitmask_enum/conflict_checker.rb', line 9 def initialize(model, attribute, defined_enum_methods) @model = model @attribute = attribute @defined_enum_methods = defined_enum_methods end |
Instance Method Details
#check_class_method!(method_name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Check if the method name is dangerous or already defined on the class
17 18 19 20 21 22 23 |
# File 'lib/bitmask_enum/conflict_checker.rb', line 17 def check_class_method!(method_name) if @model.dangerous_class_method?(method_name) raise_bitmask_conflict_error!(ActiveRecord.name, method_name, klass_method: true) elsif @model.method_defined_within?(method_name, ActiveRecord::Relation) raise_bitmask_conflict_error!(ActiveRecord::Relation.name, method_name, klass_method: true) end end |
#check_instance_method!(method_name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Check if the method name is dangerous or already defined on the instance, or defined by another bitmask enum
27 28 29 30 31 32 33 34 35 |
# File 'lib/bitmask_enum/conflict_checker.rb', line 27 def check_instance_method!(method_name) if @model.dangerous_attribute_method?(method_name) raise_bitmask_conflict_error!(ActiveRecord.name, method_name) elsif @defined_enum_methods.include?(method_name) raise_bitmask_conflict_error!(@defined_enum_methods[method_name], method_name) end @defined_enum_methods[method_name] = @attribute end |