Module: Records::Base
- Extended by:
- ActiveSupport::Concern
- Included in:
- ApplicationRecord
- Defined in:
- app/models/concerns/records/base.rb
Instance Method Summary collapse
- #all_blank?(attributes = {}) ⇒ Boolean
-
#label_string ⇒ Object
this is a template method you can override in activerecord models if we shouldn’t just use their first string to identify them.
- #parent_collection ⇒ Object
- #seeding? ⇒ Boolean
Instance Method Details
#all_blank?(attributes = {}) ⇒ Boolean
73 74 75 76 77 78 79 80 |
# File 'app/models/concerns/records/base.rb', line 73 def all_blank?(attributes = {}) attributes = self.attributes if attributes.empty? attributes.all? do |key, value| key == "_destroy" || value.blank? || value.is_a?(Hash) && all_blank?(value) || value.is_a?(Array) && value.all? { |val| all_blank?(val) } end end |
#label_string ⇒ Object
this is a template method you can override in activerecord models if we shouldn’t just use their first string to identify them.
53 54 55 56 57 58 59 |
# File 'app/models/concerns/records/base.rb', line 53 def label_string if (label_attribute = self.class.label_attribute) send(:"#{label_attribute}_was") else self.class.name.underscore.split("/").last.titleize end end |
#parent_collection ⇒ Object
61 62 63 64 65 66 67 |
# File 'app/models/concerns/records/base.rb', line 61 def parent_collection # TODO Try to suggest what the entire method definition should actually be # using parent_key below to do so. model_name = self.class # parent_key = model_name.reflect_on_all_associations(:belongs_to).first.name raise "You're trying to use a feature that requires #{model_name} to have a `collection` method defined that returns the Active Record association that this model belongs to within its parent object." end |
#seeding? ⇒ Boolean
69 70 71 |
# File 'app/models/concerns/records/base.rb', line 69 def seeding? Rake::Task.task_defined?("db:seed") && Rake::Task["db:seed"].already_invoked end |