Skip to content

Commit

Permalink
Model documentation (#37)
Browse files Browse the repository at this point in the history
* added yard gem

* add error documentation

* readd error, will remove on merge

* add yardoc files to gitignore

* remove ignored files

* will put error docs in separate branch

* add error comments

* remove check_configs and check_completed errors, methods, and tests

* remove yard from gemspec

* documentation for public core methods

* core-documentation

* initial model documentation

* minor doc updateS
  • Loading branch information
inveterateliterate authored Apr 25, 2017
1 parent e2ff378 commit 1dd4d5d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
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

0 comments on commit 1dd4d5d

Please sign in to comment.