-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Fix ClassMethods file and class name - Auto load ActiveRecord models - Fix generators - `judge.public_send` in favor of bare `send`
- Loading branch information
Showing
38 changed files
with
155 additions
and
83 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...nerators/active_record/merit_generator.rb → ...nerators/active_record/merit_generator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require "rails/generators" | ||
|
||
module Merit | ||
module Generators | ||
class InstallGenerator < ::Rails::Generators::Base | ||
source_root File.expand_path('../templates', __FILE__) | ||
hook_for :orm | ||
|
||
desc 'Copy config and rules files' | ||
def copy_migrations_and_model | ||
template 'merit.erb', 'config/initializers/merit.rb' | ||
template 'merit_badge_rules.erb', 'app/models/merit/badge_rules.rb' | ||
template 'merit_point_rules.erb', 'app/models/merit/point_rules.rb' | ||
template 'merit_rank_rules.erb', 'app/models/merit/rank_rules.rb' | ||
end | ||
end | ||
end | ||
end |
4 changes: 3 additions & 1 deletion
4
lib/generators/merit/merit_generator.rb → lib/merit/generators/merit_generator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
lib/generators/merit/remove_generator.rb → lib/merit/generators/remove_generator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 5 additions & 1 deletion
6
...erit/models/active_record/merit/action.rb → lib/merit/models/active_record/action.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
module Merit | ||
module Merit::Models::ActiveRecord | ||
class Action < ActiveRecord::Base | ||
include Merit::Models::ActionConcern | ||
|
||
self.table_name = :merit_actions | ||
|
||
has_many :activity_logs, class_name: 'Merit::ActivityLog' | ||
end | ||
end | ||
|
||
class Merit::Action < Merit::Models::ActiveRecord::Action; end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module Merit::Models | ||
module BadgesSashConcern | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
belongs_to :sash | ||
end | ||
|
||
def badge | ||
Merit::Badge.find(badge_id) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module Merit | ||
module Base | ||
module Models::Base | ||
module BadgesSash | ||
extend ActiveSupport::Concern | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module Merit | ||
module Base | ||
module Models::Base | ||
module Sash | ||
def badges | ||
badge_ids.map { |id| Merit::Badge.find id } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
module Merit::Models | ||
module SashConcern | ||
def badges | ||
badge_ids.map { |id| Merit::Badge.find id } | ||
end | ||
|
||
def badge_ids | ||
badges_sashes.map(&:badge_id) | ||
end | ||
|
||
def add_badge(badge_id) | ||
bs = Merit::BadgesSash.new(badge_id: badge_id.to_i) | ||
badges_sashes << bs | ||
bs | ||
end | ||
|
||
def rm_badge(badge_id) | ||
badges_sashes.where(badge_id: badge_id.to_i).first.try(:destroy) | ||
end | ||
|
||
# Retrieve the number of points from a category | ||
# By default all points are summed up | ||
# @param category [String] The category | ||
# @return [Integer] The number of points | ||
def points(options = {}) | ||
if (category = options[:category]) | ||
scores.where(category: category).first.try(:points) || 0 | ||
else | ||
scores.reduce(0) { |sum, score| sum + score.points } | ||
end | ||
end | ||
|
||
def add_points(num_points, options = {}) | ||
point = Merit::Score::Point.new | ||
point.num_points = num_points | ||
scores | ||
.where(category: options[:category] || 'default') | ||
.first_or_create | ||
.score_points << point | ||
point | ||
end | ||
|
||
def subtract_points(num_points, options = {}) | ||
add_points(-num_points, options) | ||
end | ||
|
||
private | ||
|
||
def create_scores | ||
scores << Merit::Score.create | ||
end | ||
end | ||
end |
File renamed without changes.
File renamed without changes.
Oops, something went wrong.