Module: Specstar::Models::Matchers
- Defined in:
- lib/specstar/models/attributes.rb,
lib/specstar/models/validations.rb,
lib/specstar/models/associations.rb
Instance Method Summary collapse
- #has_association?(model, association) ⇒ Boolean
- #has_attribute?(model, attr, extras = {}) ⇒ Boolean
- #match?(association, options) ⇒ Boolean
- #undefined_method_in_options(model, options) ⇒ Object
- #validate_presence_of_methods_in_options(model, options) ⇒ Object
Instance Method Details
#has_association?(model, association) ⇒ Boolean
46 47 48 |
# File 'lib/specstar/models/validations.rb', line 46 def has_association?(model, association) model.class.reflect_on_all_associations.map { |a| a.name.to_s }.include? association.to_s end |
#has_attribute?(model, attr, extras = {}) ⇒ Boolean
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/specstar/models/validations.rb', line 31 def has_attribute?(model, attr, extras={}) attr = attr.to_s result = model.attributes.include? attr if result && extras.any? properties = model.class.columns_hash[attr] extras.each_pair do |property, value| result = false && break unless properties.send(property).to_s == value.to_s end end result end |
#match?(association, options) ⇒ Boolean
8 9 10 11 12 |
# File 'lib/specstar/models/associations.rb', line 8 def match?(association, ) .each_pair.select do |key, value| association.[key.to_sym].to_s != value.to_s end.size == 0 end |
#undefined_method_in_options(model, options) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/specstar/models/validations.rb', line 19 def (model, ) if [:if] && [:if].is_a?(Symbol) return [:if] unless model.respond_to? [:if] end if [:unless] && [:unless].is_a?(Symbol) return [:unless] unless model.respond_to? [:unless] end nil end |
#validate_presence_of_methods_in_options(model, options) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/specstar/models/validations.rb', line 7 def (model, ) if [:if] && [:if].is_a?(Symbol) return false unless model.respond_to? [:if] end if [:unless] && [:unless].is_a?(Symbol) return false unless model.respond_to? [:unless] end true end |