Class: ForeignKeyValidation::Collector
- Inherits:
-
Object
- Object
- ForeignKeyValidation::Collector
- Defined in:
- lib/foreign_key_validation/collector.rb
Constant Summary collapse
- DEFAULT_VALIDATE_AGAINST =
:user
Instance Attribute Summary collapse
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#reflection_names ⇒ Object
Returns the value of attribute reflection_names.
-
#reflections ⇒ Object
Returns the value of attribute reflections.
-
#validate_against ⇒ Object
Returns the value of attribute validate_against.
-
#validate_against_key ⇒ Object
Returns the value of attribute validate_against_key.
-
#validate_with ⇒ Object
Returns the value of attribute validate_with.
Instance Method Summary collapse
- #check! ⇒ Object
-
#initialize(opt = {}) ⇒ Collector
constructor
A new instance of Collector.
Constructor Details
#initialize(opt = {}) ⇒ Collector
Returns a new instance of Collector.
8 9 10 11 12 13 14 15 |
# File 'lib/foreign_key_validation/collector.rb', line 8 def initialize(opt={}) self.klass = opt[:klass] self.validate_against = find_validate_against(opt[:on]) self.reflections = klass.reflect_on_all_associations(:belongs_to) self.reflection_names = reflections.map(&:name).map(&:to_s) self.validate_against_key = find_validate_against_key self.validate_with = find_validate_with(opt[:with]) end |
Instance Attribute Details
#klass ⇒ Object
Returns the value of attribute klass.
4 5 6 |
# File 'lib/foreign_key_validation/collector.rb', line 4 def klass @klass end |
#reflection_names ⇒ Object
Returns the value of attribute reflection_names.
4 5 6 |
# File 'lib/foreign_key_validation/collector.rb', line 4 def reflection_names @reflection_names end |
#reflections ⇒ Object
Returns the value of attribute reflections.
4 5 6 |
# File 'lib/foreign_key_validation/collector.rb', line 4 def reflections @reflections end |
#validate_against ⇒ Object
Returns the value of attribute validate_against.
4 5 6 |
# File 'lib/foreign_key_validation/collector.rb', line 4 def validate_against @validate_against end |
#validate_against_key ⇒ Object
Returns the value of attribute validate_against_key.
4 5 6 |
# File 'lib/foreign_key_validation/collector.rb', line 4 def validate_against_key @validate_against_key end |
#validate_with ⇒ Object
Returns the value of attribute validate_with.
4 5 6 |
# File 'lib/foreign_key_validation/collector.rb', line 4 def validate_with @validate_with end |
Instance Method Details
#check! ⇒ Object
17 18 19 20 21 22 |
# File 'lib/foreign_key_validation/collector.rb', line 17 def check! raise Errors::NoReleationFoundError.new(klass.name) if reflection_names.empty? raise Errors::NoForeignKeyFoundError.new(validate_against, klass.table_name) unless reflection_names.include?(validate_against) raise Errors::UnknownRelationError.new(validate_with) unless validate_with.all? {|k| reflection_names.include?(k)} true end |