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



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/models/concerns/shared/is_data.rb', line 39

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



32
33
34
35
# File 'app/models/concerns/shared/is_data.rb', line 32

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

#dwc_occurrence_eligible?Boolean

Returns:

  • (Boolean)


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

def dwc_occurrence_eligible?
  self < Shared::IsDwcOccurrence
end

#identical(attr) ⇒ Scope

Parameters:

  • attr (Hash)

    of matchable attributes

Returns:

  • (Scope)


80
81
82
83
84
85
86
# File 'app/models/concerns/shared/is_data.rb', line 80

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

  scope = klass.where(attr)
  scope
end

#is_community?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'app/models/concerns/shared/is_data.rb', line 23

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

#similar(attr) ⇒ Scope

Parameters:

  • attr (Hash)

    of matchable attributes

Returns:

  • (Scope)


69
70
71
72
73
74
75
76
# File 'app/models/concerns/shared/is_data.rb', line 69

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