-
Notifications
You must be signed in to change notification settings - Fork 4
Instructions
Andy Maleh edited this page Apr 8, 2015
·
2 revisions
Using Bundler
Add the following to Gemfile:
gem 'super_module', '1.0.0'
And run the following command:
bundle
Afterwards, SuperModule will automatically get required in the application (e.g. a Rails application) and be ready for use.
Using RubyGem Directly
Run the following command:
gem install super_module
(add --no-ri --no-rdoc
if you wish to skip downloading documentation for a faster install)
Add the following at the top of your Ruby file:
require 'super_module'
2) Include SuperModule
at the top of the module
module UserIdentifiable
include SuperModule
include ActiveModel::Model
belongs_to :user
validates :user_id, presence: true
def self.most_active_user
User.find_by_id(select('count(id) as head_count, user_id').group('user_id').order('count(id) desc').first.user_id)
end
def slug
"#{self.class.name}_#{user_id}"
end
end
class ClubParticipation < ActiveRecord::Base
include UserIdentifiable
end
class CourseEnrollment < ActiveRecord::Base
include UserIdentifiable
end
module Accountable
include SuperModule
include UserIdentifiable
end
class Activity < ActiveRecord::Base
include Accountable
end
CourseEnrollment.most_active_user
ClubParticipation.most_active_user
Activity.last.slug
ClubParticipation.create(club_id: club.id, user_id: user.id).slug
CourseEnrollment.new(course_id: course.id).valid?