Module: Shared::IsData::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

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

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



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/models/concerns/shared/is_data.rb', line 32

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).each do |li|
        li.update(attribute => value)
      end
    end
  rescue
    return false
  end
  true
end

#data_attributesArray

Returns of strings of only the non-cached and non-housekeeping column names.

Returns:

  • (Array)

    of strings of only the non-cached and non-housekeeping column names



25
26
27
28
# File 'app/models/concerns/shared/is_data.rb', line 25

def data_attributes
  column_names.reject { |c| %w{id project_id created_by_id updated_by_id created_at updated_at}
    .include?(c) || c =~ /^cached/ }
end

#identical(attr) ⇒ Scope

Parameters:

  • attr (Hash)

    of matchable attributes

Returns:

  • (Scope)


73
74
75
76
77
78
79
# File 'app/models/concerns/shared/is_data.rb', line 73

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

  scope = klass.where(attr)
  scope
end

#is_community?Boolean

Returns:

  • (Boolean)


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

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

#similar(attr) ⇒ Scope

Parameters:

  • attr (Hash)

    of matchable attributes

Returns:

  • (Scope)


62
63
64
65
66
67
68
69
# File 'app/models/concerns/shared/is_data.rb', line 62

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