Sha256: d4e65721d9f0ca3dd15c662d39eee35df8c9180d43a946913a0f2c33d334e305

Contents?: true

Size: 758 Bytes

Versions: 1

Compression:

Stored size: 758 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})
            true
          end

          # When calling the attribute name, convert its value
          def #{attribute}
            Emojimmy.token_to_emoji(super)
          end
        RUBY
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
emojimmy-0.3 lib/emojimmy/mixin.rb