Sha256: 018734d341b2b909c8110a470dce6f94a5d8c516857dbbebb7d2d710b53be5a3

Contents?: true

Size: 863 Bytes

Versions: 7

Compression:

Stored size: 863 Bytes

Contents

module Flexite
  class Entry < ActiveRecord::Base
    include WithHistory

    attr_accessible :value
    history_attributes :value

    belongs_to :parent, polymorphic: true, touch: true
    has_many :histories, as: :entity, dependent: :destroy
    scope :order_by_value, -> { order(:value) }

    before_save :check_value, :cast_value

    def self.form(attributes = {})
      Form.new(attributes)
    end

    def self.service(type)
      "entry_#{type}".to_sym
    end

    alias :form_attributes :attributes

    def t_node
      {
        'value' => self[:value],
        'type' => I18n.t("models.#{self.class.name.demodulize.underscore}"),
        'class' => self.class.name
      }
    end

    def dig(level)
      send(level)
    end

    private

    def cast_value
      self[:value] = self[:value].to_s
    end

    def check_value
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
flexite-0.0.25 app/models/flexite/entry.rb
flexite-0.0.24 app/models/flexite/entry.rb
flexite-0.0.23 app/models/flexite/entry.rb
flexite-0.0.22 app/models/flexite/entry.rb
flexite-0.0.21 app/models/flexite/entry.rb
flexite-0.0.20 app/models/flexite/entry.rb
flexite-0.0.19 app/models/flexite/entry.rb