Sha256: 314b1d56ee20c909b8dd2ae1f69a2bc435479862063cca2158827ffc6786fa76

Contents?: true

Size: 646 Bytes

Versions: 1

Compression:

Stored size: 646 Bytes

Contents

module Troo
  module ModelHelpers
    module ClassMethods
      def first(criteria = {})
        return all.first if criteria.nil? || criteria.empty?
        find(criteria).first
      end

      def update(criteria = {})
        return false if criteria.nil? || criteria.empty?
        all.map { |record| record.update(criteria) }
        true
      end

      def default
        first(default: true)
      end

      def count
        all.count
      end
    end

    def self.included(base)
      base.extend(ClassMethods)
    end

    def external_attributes
      attributes.delete_if { |k, _| k == :id || k == :default }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
troo-0.0.8 lib/troo/helpers/model_helpers.rb