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
mdg-1.0.1 vendor/bundle/ruby/2.3.0/gems/activerecord-3.2.22.5/lib/active_record/readonly_attributes.rb
activerecord-3.2.22.5 lib/active_record/readonly_attributes.rb
activerecord-3.2.22.4 lib/active_record/readonly_attributes.rb
activerecord-3.2.22.3 lib/active_record/readonly_attributes.rb
activerecord-3.2.22.2 lib/active_record/readonly_attributes.rb
activerecord-3.2.22.1 lib/active_record/readonly_attributes.rb
active_mailer-0.0.10 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/readonly_attributes.rb
activerecord-3.2.22 lib/active_record/readonly_attributes.rb
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/activerecord-3.2.12/lib/active_record/readonly_attributes.rb
activerecord-3.2.21 lib/active_record/readonly_attributes.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/2.1.0/gems/activerecord-3.2.18/lib/active_record/readonly_attributes.rb
apl-library-0.0.90 vendor/bundle/ruby/1.8/gems/activerecord-3.2.18/lib/active_record/readonly_attributes.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.18/lib/active_record/readonly_attributes.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/activerecord-3.2.18/lib/active_record/readonly_attributes.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.8/gems/activerecord-3.2.18/lib/active_record/readonly_attributes.rb
apl-library-0.0.90 vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.18/lib/active_record/readonly_attributes.rb
activerecord-3.2.20 lib/active_record/readonly_attributes.rb
activerecord-3.2.19 lib/active_record/readonly_attributes.rb
activerecord-3.2.18 lib/active_record/readonly_attributes.rb
activerecord-3.2.17 lib/active_record/readonly_attributes.rb