Sha256: 8dffec65eb5d04001b3e64c232ca3aeacaca4c3ae4430678d6796926bb23f032

Contents?: true

Size: 760 Bytes

Versions: 138

Compression:

Stored size: 760 Bytes

Contents

require 'active_support/concern'
require 'active_support/core_ext/class/attribute'

module ActiveRecord
  module ReadonlyAttributes
    extend ActiveSupport::Concern

    included do
      class_attribute :_attr_readonly, :instance_writer => false
      self._attr_readonly = []
    end

    module ClassMethods
      # Attributes listed as readonly will be used to create a new record but update operations will
      # ignore these fields.
      def attr_readonly(*attributes)
        self._attr_readonly = Set.new(attributes.map { |a| a.to_s }) + (self._attr_readonly || [])
      end

      # Returns an array of all the attributes that have been specified as readonly.
      def readonly_attributes
        self._attr_readonly
      end
    end
  end
end

Version data entries

138 entries across 107 versions & 14 rubygems

Version Path
challah-0.6.1 vendor/bundle/gems/activerecord-3.2.1/lib/active_record/readonly_attributes.rb
activerecord-3.2.5 lib/active_record/readonly_attributes.rb
activerecord-3.2.4 lib/active_record/readonly_attributes.rb
activerecord-3.2.4.rc1 lib/active_record/readonly_attributes.rb
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.3/lib/active_record/readonly_attributes.rb
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.3/lib/active_record/readonly_attributes.rb
rails-uploader-0.0.1 vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.3/lib/active_record/readonly_attributes.rb
challah-0.6.0 vendor/bundle/gems/activerecord-3.2.3/lib/active_record/readonly_attributes.rb
challah-0.6.0 vendor/bundle/gems/activerecord-3.2.1/lib/active_record/readonly_attributes.rb
challah-0.6.0 vendor/bundle/gems/activerecord-3.2.2/lib/active_record/readonly_attributes.rb
challah-0.5.4 vendor/bundle/gems/activerecord-3.2.2/lib/active_record/readonly_attributes.rb
challah-0.5.4 vendor/bundle/gems/activerecord-3.2.1/lib/active_record/readonly_attributes.rb
activerecord-3.2.3 lib/active_record/readonly_attributes.rb
activerecord-3.2.3.rc2 lib/active_record/readonly_attributes.rb
activerecord-3.2.3.rc1 lib/active_record/readonly_attributes.rb
challah-0.5.3 vendor/bundle/gems/activerecord-3.2.2/lib/active_record/readonly_attributes.rb
challah-0.5.3 vendor/bundle/gems/activerecord-3.2.1/lib/active_record/readonly_attributes.rb
challah-0.5.2 vendor/bundle/gems/activerecord-3.2.2/lib/active_record/readonly_attributes.rb
challah-0.5.2 vendor/bundle/gems/activerecord-3.2.1/lib/active_record/readonly_attributes.rb
challah-0.5.1 vendor/bundle/gems/activerecord-3.2.2/lib/active_record/readonly_attributes.rb