Sha256: 853d97c9b3aac141d65dfcf5009d85409f8b6f686d22be2b905eec1866e20861

Contents?: true

Size: 1.03 KB

Versions: 6

Compression:

Stored size: 1.03 KB

Contents

module Storytime
  module Concerns
    module StorytimeUser
      extend ActiveSupport::Concern

      module ClassMethods
        def storytime_user
          belongs_to :storytime_role, class_name: "Storytime::Role"
          has_many :storytime_posts, class_name: "Storytime::Post"
          has_many :storytime_pages, class_name: "Storytime::Page"
          has_many :storytime_media, class_name: "Storytime::Media"
          has_many :storytime_versions, class_name: "Storytime::Version"
          has_many :storytime_comments, class_name: "Storytime::Comment"

          class_eval <<-EOS
            def storytime_user?
              !storytime_role.nil?
            end
          EOS

          %w{admin editor writer}.each do |role_name|
            class_eval <<-EOS
              def storytime_#{role_name}?
                storytime_role && storytime_role.name == "#{role_name}"
              end
            EOS
          end  
        end
      end

    end
  end
end

ActiveRecord::Base.send :include, Storytime::Concerns::StorytimeUser

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
storytime-1.0.5 lib/storytime/concerns/storytime_user.rb
storytime-1.0.2 lib/storytime/concerns/storytime_user.rb
storytime-1.0.1 lib/storytime/concerns/storytime_user.rb
storytime-1.0.0 lib/storytime/concerns/storytime_user.rb
storytime-0.0.4 lib/storytime/concerns/storytime_user.rb
storytime-0.0.2 lib/storytime/concerns/storytime_user.rb