Sha256: c36bd01e756870c5bcfce736426ae29423642f8a1f42bad470be432497a374fe

Contents?: true

Size: 603 Bytes

Versions: 1

Compression:

Stored size: 603 Bytes

Contents

module Emotions
  module Emotive
    extend ActiveSupport::Concern

    included do
      has_many :emotions, as: :emotive, class_name: 'Emotions::Emotion'

      Emotions.emotions.each do |emotion|
        define_emotion_methods(emotion)
      end
    end

    def emotional_about
      self.emotions.includes(:emotional)
    end

    module ClassMethods
      def define_emotion_methods(emotion)
        class_eval <<-RUBY, __FILE__, __LINE__ + 1
          def #{emotion}_about
            emotional_about.where(emotion: #{emotion.to_s.inspect})
          end
        RUBY
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
emotions-0.1.1 lib/emotions/emotive.rb