Class: SimpleTeams::MembershipForm
- Inherits:
-
ApplicationForm
- Object
- ApplicationForm
- SimpleTeams::MembershipForm
- Defined in:
- app/forms/simple_teams/membership_form.rb
Instance Attribute Summary collapse
-
#current_user ⇒ Object
Returns the value of attribute current_user.
-
#membership ⇒ Object
Returns the value of attribute membership.
-
#role ⇒ Object
Returns the value of attribute role.
Instance Method Summary collapse
- #available_roles ⇒ Object
-
#initialize(membership, current_user) ⇒ MembershipForm
constructor
A new instance of MembershipForm.
- #perform(params) ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(membership, current_user) ⇒ MembershipForm
Returns a new instance of MembershipForm.
6 7 8 9 10 11 12 |
# File 'app/forms/simple_teams/membership_form.rb', line 6 def initialize(membership, current_user) @membership = membership @current_user = current_user # Get existing attributes @role = @membership.role end |
Instance Attribute Details
#current_user ⇒ Object
Returns the value of attribute current_user.
4 5 6 |
# File 'app/forms/simple_teams/membership_form.rb', line 4 def current_user @current_user end |
#membership ⇒ Object
Returns the value of attribute membership.
4 5 6 |
# File 'app/forms/simple_teams/membership_form.rb', line 4 def membership @membership end |
#role ⇒ Object
Returns the value of attribute role.
4 5 6 |
# File 'app/forms/simple_teams/membership_form.rb', line 4 def role @role end |
Instance Method Details
#available_roles ⇒ Object
34 35 36 |
# File 'app/forms/simple_teams/membership_form.rb', line 34 def available_roles SimpleTeams::Membership.roles end |
#perform(params) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'app/forms/simple_teams/membership_form.rb', line 23 def perform(params) self.assign_attributes(params) if valid? membership.update(params) generate_notification else false end end |
#valid? ⇒ Boolean
14 15 16 17 18 19 20 21 |
# File 'app/forms/simple_teams/membership_form.rb', line 14 def valid? self.errors.clear validate_role_is_available validate_current_user_has_rights_to_modify_an_existing_owner validate_current_user_has_rights_to_add_an_owner validate_not_last_owner !self.errors.present? end |