This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// include the filesystem module | |
var fs = require('fs'); | |
// fs.readFile: read a file and all its contents, | |
// then call a callback function | |
fs.readFile('/some/file', function (err, contents) { | |
// if any error occurred, throw it | |
if (err) throw err; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Put this file under Rails.root /lib | |
class CssColourValidator < ActiveModel::EachValidator | |
def validate_each(record, attribute, value) | |
return false unless value | |
record.errors[attribute] << (options[:message] || 'is not a valid CSS colour') unless ::HexadecimalColourValidator.matches?(value) or ::WebSafeColourValidator.matches?(value) | |
end | |
end |
NewerOlder