Commit 47eb5880 by Colin Rice

Adding a hook to store emojis in db dynamically.

parent db6bf446
# -*- encoding: utf-8 -*-
require 'rumoji/mixin'
require 'rumoji/extensions'
module Rumoji
class Emoji
......
class ApplicationRecord
def self.stores_emoji_characters(*attributes)
return unless table_exists?
Rumoji::Mixin.inject_methods(self, attributes)
end
end
\ No newline at end of file
module Rumoji
module Mixin
def self.inject_methods(model, attributes)
attributes.each do |attribute|
model.class_eval <<-RUBY, __FILE__, __LINE__ + 1
before_save do
unless respond_to?("#{attribute}=")
raise ArgumentError.new('#{model} must respond to #{attribute}= in order for Rumoji to store emoji.')
end
self.#{attribute} = Rumoji.encode(self.#{attribute})
true
end
def #{attribute}
Rumoji.decode(super)
end
RUBY
end
end
end
end
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment