Module: AttributeAccessControllable

Extended by:
ActiveSupport::Concern
Defined in:
lib/attribute_access_controllable.rb

Instance Method Summary collapse

Instance Method Details

#attr_read_only(*attributes) ⇒ void

This method returns an undefined value.

Mark an attribute as read-only

Parameters:

  • attributes (Symbol)

    on the model



14
15
16
# File 'lib/attribute_access_controllable.rb', line 14

def attr_read_only(*attributes)
  self.read_only_attributes = Set.new(attributes.map { |a| a.to_s }) + (read_only_attributes || [])
end

#read_only_attribute?(attribute) ⇒ Boolean

Returns attribute is read-only.

Parameters:

  • attribute (Symbol)

    on the model

Returns:

  • (Boolean)

    attribute is read-only



20
21
22
23
# File 'lib/attribute_access_controllable.rb', line 20

def read_only_attribute?(attribute)
  return false if read_only_attributes.nil?
  read_only_attributes.member?(attribute.to_s)
end

#save(options = {}) ⇒ Object



25
26
27
28
# File 'lib/attribute_access_controllable.rb', line 25

def save(options = {})
  self.skip_read_only = options.delete(:skip_read_only)
  super
end

#save!(options = {}) ⇒ Object



30
31
32
33
# File 'lib/attribute_access_controllable.rb', line 30

def save!(options = {})
  self.skip_read_only = options.delete(:skip_read_only)
  super
end