Module: Shared::IsData::ClassMethods

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

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) annotates?

true if model is an “annotator” (e.g. identifiers, tags, notes, data attributes, alternate values, citations), i.e. data that references another data element through STI

Returns:

  • (Boolean)


102
103
104
# File 'app/models/concerns/shared/is_data.rb', line 102

def annotates?
  self.respond_to?(:annotated_object)
end

- (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



126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'app/models/concerns/shared/is_data.rb', line 126

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

- (Boolean) is_community?

Returns:

  • (Boolean)


96
97
98
# File 'app/models/concerns/shared/is_data.rb', line 96

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

- (Scope) not_ids(*ids)

! Not built for collisions

Returns:

  • (Scope)


120
121
122
# File 'app/models/concerns/shared/is_data.rb', line 120

def not_ids(*ids)
  where.not(id: ids)
end

- (Scope) not_self(object)

a where clause that excludes the present object from being selected

Returns:

  • (Scope)


108
109
110
111
112
113
114
# File 'app/models/concerns/shared/is_data.rb', line 108

def not_self(object)
  if object.nil? || object.id.blank?
    where(object.class.table_name => {id: '<> 0'})
  else
    where(object.class.arel_table[:id].not_eq(object.to_param))
  end
end