Module: Stratagem::Instrumentation::Models::Metadata
- Included in:
- Annotations
- Defined in:
- lib/stratagem/instrumentation/models/metadata.rb
Constant Summary collapse
- INSTANCE_ENUMERATION_METHODS =
[:relations, :attribute_names, :ignore_attributes, :internal_attributes, :unaccessible_attributes, :invalid_columns, :exclude_attributes_for_mocking]
- INSTANCE_ENTITY_METHODS =
[:attribute_type, :column_from_error, :authenticates?, :whitelists_attributes?, :blacklists_attributes?]
Class Method Summary collapse
Instance Method Summary collapse
- #callbacks ⇒ Object
-
#connected_classes ⇒ Object
Convenience methods.
- #foreign_keys ⇒ Object
- #relation(name) ⇒ Object
- #relation_names(relation_type = nil) ⇒ Object
- #subclasses? ⇒ Boolean
-
#validations(field = nil, validation = nil) ⇒ Object
Tracking of validates_xyz methods.
- #validators ⇒ Object
Class Method Details
.included(mod) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/stratagem/instrumentation/models/metadata.rb', line 7 def Metadata.included(mod) mod.class_eval do INSTANCE_ENUMERATION_METHODS.each do |name| define_method(name) do |*args| run_callbacks(name, *args) end end INSTANCE_ENTITY_METHODS.each do |name| define_method(name) do |*args| val = run_callbacks(name, *args).first val ||= false if (name.to_s.include?('?')) val end end end end |
Instance Method Details
#callbacks ⇒ Object
67 68 69 70 71 |
# File 'lib/stratagem/instrumentation/models/metadata.rb', line 67 def callbacks adapters.select {|a| a.detector.supports?(model) }.map {|a| a. } end |
#connected_classes ⇒ Object
Convenience methods
28 29 30 |
# File 'lib/stratagem/instrumentation/models/metadata.rb', line 28 def connected_classes traverse_graph(model) - [model] end |
#foreign_keys ⇒ Object
36 37 38 |
# File 'lib/stratagem/instrumentation/models/metadata.rb', line 36 def foreign_keys relations(:belongs_to).map {|relation| relation.foreign_key } end |
#relation(name) ⇒ Object
40 41 42 |
# File 'lib/stratagem/instrumentation/models/metadata.rb', line 40 def relation(name) relations.find {|relation| relation.name == name } end |
#relation_names(relation_type = nil) ⇒ Object
44 45 46 47 |
# File 'lib/stratagem/instrumentation/models/metadata.rb', line 44 def relation_names(relation_type=nil) @relation_names ||= {} @relation_names[relation_type || :all] ||= relations(relation_type).map {|relation| relation.name } end |
#subclasses? ⇒ Boolean
32 33 34 |
# File 'lib/stratagem/instrumentation/models/metadata.rb', line 32 def subclasses? model.sg_subclasses().size > 0 end |
#validations(field = nil, validation = nil) ⇒ Object
Tracking of validates_xyz methods. Population of this data can be found in the tracing library
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/stratagem/instrumentation/models/metadata.rb', line 52 def validations(field=nil, validation=nil) validators = self.validators if (field || validation) validators.select {|v| conditions = [] conditions << (v.field == field) if field conditions << (v.validation == validation) if validation !conditions.include?(false) } else validators end end |
#validators ⇒ Object
73 74 75 |
# File 'lib/stratagem/instrumentation/models/metadata.rb', line 73 def validators @validators ||= [] end |