Module: Shared::IsData::ClassMethods

Defined in:
app/models/concerns/shared/is_data.rb

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) batch_update_attribute(ids: [], attribute: nil, value: nil)

Returns use update vs. a set of ids, but require the update to pass for all or none

Returns:

  • (Boolean)

    use update vs. a set of ids, but require the update to pass for all or none



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/models/concerns/shared/is_data.rb', line 25

def batch_update_attribute(ids: [], attribute: nil, value: nil)
  return false if ids.empty? || attribute.nil? || value.nil?
  begin
    self.transaction do
      self.where(id: ids).find_each do |li|
        li.update(attribute => value)
      end
    end
  rescue
    return false
  end
  true
end

- (Scope) identical(attr)

Parameters:

  • attr (Hash)

    of matchable attributes

Returns:

  • (Scope)


66
67
68
69
70
71
72
# File 'app/models/concerns/shared/is_data.rb', line 66

def identical(attr)
  klass = self
  attr  = Stripper.strip_identical_attributes(klass, attr)

  scope = klass.where(attr)
  scope
end

- (Boolean) is_community?

Returns:

  • (Boolean)


19
20
21
# File 'app/models/concerns/shared/is_data.rb', line 19

def is_community?
  self < Shared::SharedAcrossProjects ? true : false
end

- (Scope) similar(attr)

Parameters:

  • attr (Hash)

    of matchable attributes

Returns:

  • (Scope)


55
56
57
58
59
60
61
62
# File 'app/models/concerns/shared/is_data.rb', line 55

def similar(attr)
  klass = self
  attr  = Stripper.strip_similar_attributes(klass, attr)
  attr  = attr.select { |_kee, val| val.present? }

  scope = klass.where(attr)
  scope
end