Class: NextSges::CollectionType

Inherits:
ApplicationRecord show all
Defined in:
app/models/next_sges/collection_type.rb

Constant Summary

Constants inherited from ApplicationRecord

ApplicationRecord::CELL_REGEX, ApplicationRecord::DEFAULT_IDENTIFICATION_ENUM, ApplicationRecord::DEFAULT_STATUS_ENUM, ApplicationRecord::MAIL_REGEX

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

#create_number, #create_number!, map_for_filter, map_for_select

Class Method Details

.latest_codesObject

END



14
15
16
17
# File 'app/models/next_sges/collection_type.rb', line 14

def self.latest_codes
  latest_ids = NextSges::CollectionType.all.group_by{|type| type.code}.map{|code, types| types.sort_by{|type| type.created_at}.last.id}.flatten.compact.uniq
  where(id: latest_ids)
end

Instance Method Details

#increment_codeObject



45
46
47
48
49
# File 'app/models/next_sges/collection_type.rb', line 45

def increment_code
  if code == 0 || code.nil?
    self.code = (NextSges::CollectionType.all.sort_by(&:code).last&.code || 0) + 1
  end
end

#map_for_filter(method_name = :name) ⇒ Object



24
25
26
# File 'app/models/next_sges/collection_type.rb', line 24

def map_for_filter(method_name = :name)
  map_for_select(:name)
end

#map_for_select(method_name = :name) ⇒ Object

BEGIN instance methods



20
21
22
# File 'app/models/next_sges/collection_type.rb', line 20

def map_for_select(method_name = :name)
  super(:name)
end