Sha256: 66d16b623b8d0525d4f6c069a4664090f308d3273a86d535342e5dead2971589

Contents?: true

Size: 617 Bytes

Versions: 1

Compression:

Stored size: 617 Bytes

Contents

module Kangaroo
  module Model
    module DefaultAttributes
      extend ActiveSupport::Concern
      
      included do
        before_initialize do
          return true if persisted?
          
          default_attributes = self.class.default_attributes
          if default_attributes.blank?
            return true
          end

          default_attributes.each do |name, value|
            write_attribute name, value
          end
        end        
      end

      module ClassMethods
        def default_attributes
          default_get :fields => attribute_names
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kangaroo-0.1.0.alpha1 lib/kangaroo/model/default_attributes.rb