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



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

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



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

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)


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

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

  scope = klass.where(attr)
  scope
end

#is_community?Boolean

Returns:

  • (Boolean)


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

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

#similar(attr) ⇒ Scope

Parameters:

  • attr (Hash)

    of matchable attributes

Returns:

  • (Scope)


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

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