Sha256: 966698680513602fb139221369e933e1c0f376fe2d998ca83cab1c452180b484
Contents?: true
Size: 978 Bytes
Versions: 2
Compression:
Stored size: 978 Bytes
Contents
# frozen_string_literal: true module BitCore # A section of an application. class Tool < ActiveRecord::Base belongs_to :arm has_many :content_modules, class_name: "BitCore::ContentModule", foreign_key: :bit_core_tool_id, inverse_of: :tool, dependent: :destroy validates :arm, :position, :title, presence: true validates :position, numericality: { greater_than_or_equal_to: 0 }, uniqueness: { scope: :arm_id } def add_module(title_or_module) if title_or_module.class == String content_modules.build(title: title_or_module, position: next_position) else title_or_module.tap do |m| m.tool = self m.position = next_position end end end def last_position content_modules.order(:position).last.try(:position) || 0 end private def next_position last_position + 1 end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
bit_core-1.4.7 | app/models/bit_core/tool.rb |
bit_core-2.0.0.beta2 | app/models/bit_core/tool.rb |