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



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/models/concerns/shared/is_data.rb', line 43

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



36
37
38
39
# File 'app/models/concerns/shared/is_data.rb', line 36

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)


84
85
86
87
88
89
90
# File 'app/models/concerns/shared/is_data.rb', line 84

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

#is_observable?Boolean

Returns:

  • (Boolean)


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

def is_observable?
  self < Shared::Observations
end

#similar(attr) ⇒ Scope

Parameters:

  • attr (Hash)

    of matchable attributes

Returns:

  • (Scope)


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

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