Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added person decorotor to improve readability

  • Loading branch information...
commit 60858a0af7db4b2b821f6a26cc842023930d9020 1 parent 725a6c1
@seejee seejee authored
View
11 app/controllers/application_controller.rb
@@ -7,7 +7,7 @@ class ApplicationController < ActionController::Base
def current_person
begin
- @current_person ||= Clubhouse::Client::Person.new(session[:person_github_nickname])
+ @current_person ||= clubhouse_person(session[:person_github_nickname])
rescue Clubhouse::Client::PersonNotFound
end
@@ -33,4 +33,11 @@ def person_required
def login_path
Rails.env.production? ? '/auth/github' : '/auth/developer'
end
-end
+
+ private
+
+ def clubhouse_person(github_nickname)
+ PersonDecorator.new(Clubhouse::Client::Person.new(github_nickname))
+ end
+
+end
View
2  app/controllers/sessions_controller.rb
@@ -3,7 +3,7 @@ class SessionsController < ApplicationController
def create
begin
- person = Clubhouse::Client::Person.new(auth_hash['info']['nickname'])
+ person = clubhouse_person(auth_hash['info']['nickname'])
rescue Clubhouse::Client::PersonNotFound
flash[:error] = "Sorry, but we couldn't find your record in Clubhouse"
end
View
2  app/controllers/tasks_controller.rb
@@ -11,7 +11,7 @@ def create
if task.save
redirect_to @course, flash: { success: "Task created" }
else
- render :new
+ redirect_to new_course_task_path(@course)
end
end
View
14 app/decorators/person_decorator.rb
@@ -0,0 +1,14 @@
+class PersonDecorator
+ extend Forwardable
+
+ def_delegators :@person, :name, :email, :github_nickname, :permissions
+
+ def initialize(person)
+ @person = person
+ end
+
+ def has_role?(role, course)
+ membership = course.course_memberships.for_person(self).first
+ membership.has_role?(role) if membership
+ end
+end
View
5 app/models/course.rb
@@ -6,9 +6,4 @@ def people
@people ||= course_memberships.map {|cm| cm.person }
end
- def has_role?(role, person)
- membership = course_memberships.for_person(person).first
- membership.has_role?(role) if membership
- end
-
end
View
2  app/views/courses/_tasks.html.haml
@@ -1,5 +1,5 @@
= render 'tasks/list'
-- if @course.has_role?(:instructor, current_person)
+- if current_person.has_role?(:instructor, @course)
= link_to("Add Task", new_course_task_path(@course))
Please sign in to comment.
Something went wrong with that request. Please try again.