Module: AttributeAccessControllable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/attribute_access_controllable.rb
Instance Method Summary collapse
-
#attr_read_only(*attributes) ⇒ void
Mark an attribute as read-only.
-
#read_only_attribute?(attribute) ⇒ Boolean
Attribute is read-only.
- #save(options = {}) ⇒ Object
- #save!(options = {}) ⇒ Object
Instance Method Details
#attr_read_only(*attributes) ⇒ void
This method returns an undefined value.
Mark an attribute as read-only
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.
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( = {}) self.skip_read_only = .delete(:skip_read_only) super end |
#save!(options = {}) ⇒ Object
30 31 32 33 |
# File 'lib/attribute_access_controllable.rb', line 30 def save!( = {}) self.skip_read_only = .delete(:skip_read_only) super end |