Sha256: e86e3d3dcaf2c88b27087c3a1f6a62ff2906c42ec59b575daef6a1d4f82a97c6
Contents?: true
Size: 772 Bytes
Versions: 2
Compression:
Stored size: 772 Bytes
Contents
module Emojimmy module Mixin def self.inject_methods(model, attributes) attributes.each do |attribute| model.class_eval <<-RUBY, __FILE__, __LINE__ + 1 # Before saving the record, convert the attribute value before_save do unless respond_to?("#{attribute}=") raise ArgumentError.new('#{model} must respond to #{attribute}= in order for Emojimmy to store emoji characters in it.') end self.#{attribute} = Emojimmy.emoji_to_token(self.#{attribute}) end # When calling the attribute name, convert its value def #{attribute} Emojimmy.token_to_emoji(read_attribute(#{attribute.inspect})) end RUBY end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
emojimmy-0.1.4 | lib/emojimmy/mixin.rb |
emojimmy-0.1.3 | lib/emojimmy/mixin.rb |