Sha256: 2a95e4e6ade6a0ddfca357965eb8a54c140792b2fec5fe28f4af3401c1827dd2

Contents?: true

Size: 649 Bytes

Versions: 4

Compression:

Stored size: 649 Bytes

Contents

module ActsAsIcontact
  
  # Overrides methods to make a resource class read-only.  Replaces property assignments and save methods with exceptions.
  module ReadOnly
    
    # Properties of this class are read-only.
    def method_missing(method, *params)
      raise ActsAsIcontact::ReadOnlyError, "#{self.class.readable_name} is read-only!" if method.to_s =~ /(.*)=$/ 
      super
    end
    
    # Replace save methods with an exception
    def cannot_save(*arguments)
      raise ActsAsIcontact::ReadOnlyError, "Contact History is read-only!"
    end
    alias_method :save, :cannot_save
    alias_method :save!, :cannot_save
    
  end
  
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
SFEley-acts_as_icontact-0.4.2 lib/acts_as_icontact/readonly.rb
SFEley-acts_as_icontact-0.4.3 lib/acts_as_icontact/readonly.rb
acts_as_icontact-0.4.3 lib/acts_as_icontact/readonly.rb
acts_as_icontact-0.4.2 lib/acts_as_icontact/readonly.rb