Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model documentation #37

Merged
merged 17 commits into from
Apr 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions lib/token_master/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require 'securerandom'

module TokenMaster
# `TokenMaster::Core` provides the core functionality of the TokenMaster gem. The `Core` module performs all of the logic of completing tokenable actions, and provides descriptive messages of the status or abilities of calls made
# `TokenMaster::Core` provides the core functionality of the TokenMaster gem. The `Core` module performs all of the logic of completing tokenable actions, and provides descriptive messages of the status or abilities of calls made.
module Core
class << self

Expand Down Expand Up @@ -30,7 +30,7 @@ def do_by_token!(klass, key, token, **params)
model
end

# Completes the token action for a tokenable instance _without_ a token, setting the `tokenable_completed_at` to the time at completion<br /> Usually implemented when you want to complete multiple tokenable actions at once, e.g., a user completes the invite action by setting up passwords, by default also completes the confirm action
# Completes the token action for a tokenable instance _without_ a token, setting the `tokenable_completed_at` to the time at completion.<br /> Usually implemented when you want to complete multiple tokenable actions at once, e.g., a user completes the invite action by setting up passwords, by default also completes the confirm action
# @example Force a Tokenable Action (Confirm)
# user.force_confirm! =>
# <User id: 205, name: "John Smith", email: "[email protected]", confirm_token: nil, confirm_created_at: nil, confirm_sent_at: nil, confirm_completed_at: "2017-04-25 14:17:13">
Expand Down Expand Up @@ -135,10 +135,6 @@ def token_lifetime(key)
TokenMaster.config.get_token_lifetime(key.to_sym)
end

def required_params(key)
TokenMaster.config.get_required_params(key.to_sym)
end

def check_manageable!(klass, key)
raise Errors::NotTokenable, "#{klass} not #{key}able" unless manageable?(klass, key)
end
Expand Down
21 changes: 14 additions & 7 deletions lib/token_master/model.rb
Original file line number Diff line number Diff line change
@@ -1,34 +1,41 @@
module TokenMaster

# TODO
# `TokenMaster::Model` provides the interface to the app it is used in, providing access to its public methods by invoking `TokenMaster::ClassMethods` and definiing the appropriate methods on the app model(s).
module Model
# Includes `TokenMaster::Model` and extends `TokenMaster::ClassMethods` to the class it's used with (automatically included via Railties)
def self.included(base)
base.extend(ClassMethods)
end

# `TokenMaster::ClassMethods` defines methods on the tokenable Class to be used in applying TokenMaster
module ClassMethods
# TODO
# Iterates over each of the tokenables provided in the generator arguments to define the appropriate TokenMaster methods on the tokenable model
def token_master(*tokenables)
tokenables.each do |tokenable|
# instance methods
# TODO

# Defines a method on the tokenable model instance to generate a tokenable action token, e.g., `user.set_confim_token!`
define_method("set_#{tokenable}_token!") do
TokenMaster::Core.set_token!(self, tokenable)
end
# TODO

# Defines a method on the tokenable model instance to send tokenable action instructions, e.g., `user.send_confim_instructions!`. Accepts a block with app logic to send instructions.
define_method("send_#{tokenable}_instructions!") do |&email|
TokenMaster::Core.send_instructions!(self, tokenable, &email)
end
# TODO

# Defines a method on the tokenable model instance to retrieve the status of a tokenable action, e.g., `user.confim_status`
define_method("#{tokenable}_status") do
TokenMaster::Core.status(self, tokenable)
end
# TODO

# Defines a method on the tokenable model instance to force the completion of a tokenable action, e.g., `user.force_confim!`. Accepts keyword arguments for `required_params`.
define_method("force_#{tokenable}!") do |**params|
TokenMaster::Core.force_tokenable!(self, tokenable, **params)
end
# class methods
# TODO

# Defines a method on the tokenable model class to completed a tokenable action given a token, e.g., `User.confim_by_token!`. Takes the token and accepts any keyword arguments for `required_params`.
define_singleton_method("#{tokenable}_by_token!") do |token, **params|
TokenMaster::Core.do_by_token!(self, tokenable, token, **params)
end
Expand Down
1 change: 1 addition & 0 deletions lib/token_master/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module TokenMaster
# Current version of TokenMaster
VERSION = '0.0.1'.freeze
end