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

Convert code to standard style #45

Merged
merged 2 commits into from Feb 22, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 0 additions & 37 deletions .rubocop.yml

This file was deleted.

5 changes: 5 additions & 0 deletions .standard.yml
@@ -0,0 +1,5 @@
fix: true
parallel: true
ruby_version: 2.4
ignore:
- 'test/dummy/bin/*'
4 changes: 2 additions & 2 deletions Gemfile
@@ -1,7 +1,7 @@
# frozen_string_literal: true

source 'https://rubygems.org'
source "https://rubygems.org"

gemspec

gem 'codecov', require: false, group: :test
gem "codecov", require: false, group: :test
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -4,7 +4,7 @@
<br />
</p>

[![Travis](https://travis-ci.org/mikker/passwordless.svg?branch=master)](https://travis-ci.org/mikker/passwordless) [![Rubygems](https://img.shields.io/gem/v/passwordless.svg)](https://rubygems.org/gems/passwordless) [![codecov](https://codecov.io/gh/mikker/passwordless/branch/master/graph/badge.svg)](https://codecov.io/gh/mikker/passwordless)
[![Travis](https://travis-ci.org/mikker/passwordless.svg?branch=master)](https://travis-ci.org/mikker/passwordless) [![Rubygems](https://img.shields.io/gem/v/passwordless.svg)](https://rubygems.org/gems/passwordless) [![codecov](https://codecov.io/gh/mikker/passwordless/branch/master/graph/badge.svg)](https://codecov.io/gh/mikker/passwordless) [![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/testdouble/standard)

Add authentication to your Rails app without all the icky-ness of passwords.

Expand Down
22 changes: 12 additions & 10 deletions Rakefile
@@ -1,27 +1,29 @@
# frozen_string_literal: true

begin
require 'bundler/setup'
require "bundler/setup"
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
puts "You must `gem install bundler` and `bundle install` to run rake tasks"
end

require 'yard'
require "yard"
YARD::Rake::YardocTask.new
task docs: :yard

APP_RAKEFILE = File.expand_path('../test/dummy/Rakefile', __FILE__)
load 'rails/tasks/engine.rake'
load 'rails/tasks/statistics.rake'
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
load "rails/tasks/engine.rake"
load "rails/tasks/statistics.rake"

require 'bundler/gem_tasks'
require "bundler/gem_tasks"

require 'rake/testtask'
require "rake/testtask"

Rake::TestTask.new(:test) do |t|
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.libs << "test"
t.pattern = "test/**/*_test.rb"
t.verbose = false
end

task default: :test

require "standard/rake"
7 changes: 2 additions & 5 deletions app/controllers/passwordless/sessions_controller.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'bcrypt'
require "bcrypt"

module Passwordless
# Controller for managing Passwordless sessions
Expand Down Expand Up @@ -32,8 +32,6 @@ def create
render
end

# rubocop:disable Metrics/MethodLength, Metrics/AbcSize

# get '/sign_in/:token'
# Looks up session record by provided token. Signs in user if a match
# is found. Redirects to either the user's original destination
Expand All @@ -58,10 +56,9 @@ def show
redirect_to main_app.root_path
end
rescue SessionTimedOutError
flash[:error] = I18n.t('.passwordless.sessions.create.session_expired')
flash[:error] = I18n.t(".passwordless.sessions.create.session_expired")
redirect_to main_app.root_path
end
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize

# match '/sign_out', via: %i[get delete].
# Signs user out. Redirects to root_path
Expand Down
4 changes: 2 additions & 2 deletions app/mailers/passwordless/mailer.rb
Expand Up @@ -11,12 +11,12 @@ def magic_link(session)
@session = session

@magic_link = send(Passwordless.mounted_as)
.token_sign_in_url(session.token)
.token_sign_in_url(session.token)

email_field = @session.authenticatable.class.passwordless_email_field
mail(
to: @session.authenticatable.send(email_field),
subject: I18n.t('passwordless.mailer.subject')
subject: I18n.t("passwordless.mailer.subject")
)
end
end
Expand Down
6 changes: 3 additions & 3 deletions app/models/passwordless/session.rb
Expand Up @@ -19,7 +19,7 @@ class Session < ApplicationRecord
before_validation :set_defaults

scope :valid, lambda {
where('timeout_at > ?', Time.current)
where("timeout_at > ?", Time.current)
}

def expired?
Expand All @@ -35,10 +35,10 @@ def timed_out?
def set_defaults
self.expires_at ||= Passwordless.expires_at.call
self.timeout_at ||= Passwordless.timeout_at.call
self.token ||= loop do
self.token ||= loop {
token = Passwordless.token_generator.call(self)
break token unless Session.find_by(token: token)
end
}
end
end
end
8 changes: 4 additions & 4 deletions config/routes.rb
@@ -1,8 +1,8 @@
# frozen_string_literal: true

Passwordless::Engine.routes.draw do
get '/sign_in', to: 'sessions#new', as: :sign_in
post '/sign_in', to: 'sessions#create'
get '/sign_in/:token', to: 'sessions#show', as: :token_sign_in
match '/sign_out', to: 'sessions#destroy', via: %i[get delete], as: :sign_out
get "/sign_in", to: "sessions#new", as: :sign_in
post "/sign_in", to: "sessions#create"
get "/sign_in/:token", to: "sessions#show", as: :token_sign_in
match "/sign_out", to: "sessions#destroy", via: %i[get delete], as: :sign_out
end
2 changes: 1 addition & 1 deletion db/migrate/20171104221735_create_passwordless_sessions.rb
Expand Up @@ -6,7 +6,7 @@ def change
t.belongs_to(
:authenticatable,
polymorphic: true,
index: { name: 'authenticatable' }
index: {name: "authenticatable"}
)
t.datetime :timeout_at, null: false
t.datetime :expires_at, null: false
Expand Down
6 changes: 3 additions & 3 deletions lib/passwordless.rb
@@ -1,11 +1,11 @@
# frozen_string_literal: true

require 'passwordless/engine'
require 'passwordless/url_safe_base_64_generator'
require "passwordless/engine"
require "passwordless/url_safe_base_64_generator"

# The main Passwordless module
module Passwordless
mattr_accessor(:default_from_address) { 'CHANGE_ME@example.com' }
mattr_accessor(:default_from_address) { "CHANGE_ME@example.com" }
mattr_accessor(:token_generator) { UrlSafeBase64Generator.new }
mattr_accessor(:redirect_back_after_sign_in) { true }
mattr_accessor(:mounted_as) { :configured_when_mounting_passwordless }
Expand Down
6 changes: 3 additions & 3 deletions lib/passwordless/controller_helpers.rb
Expand Up @@ -12,7 +12,7 @@ module ControllerHelpers
def build_passwordless_session(authenticatable)
Session.new.tap do |us|
us.remote_addr = request.remote_addr
us.user_agent = request.env['HTTP_USER_AGENT']
us.user_agent = request.env["HTTP_USER_AGENT"]
us.authenticatable = authenticatable
end
end
Expand All @@ -38,7 +38,7 @@ def authenticate_by_cookie(authenticatable_class)
# @return [ActiveRecord::Base] the record that is passed in.
def sign_in(authenticatable)
key = cookie_name(authenticatable.class)
cookies.encrypted.permanent[key] = { value: authenticatable.id }
cookies.encrypted.permanent[key] = {value: authenticatable.id}
authenticatable
end

Expand All @@ -47,7 +47,7 @@ def sign_in(authenticatable)
# @return [boolean] Always true
def sign_out(authenticatable_class)
key = cookie_name(authenticatable_class)
cookies.encrypted.permanent[key] = { value: nil }
cookies.encrypted.permanent[key] = {value: nil}
cookies.delete(key)
true
end
Expand Down
8 changes: 4 additions & 4 deletions lib/passwordless/engine.rb
Expand Up @@ -6,16 +6,16 @@ class Engine < ::Rails::Engine
isolate_namespace Passwordless

config.to_prepare do
require 'passwordless/router_helpers'
require "passwordless/router_helpers"
ActionDispatch::Routing::Mapper.include RouterHelpers
require 'passwordless/model_helpers'
require "passwordless/model_helpers"
ActiveRecord::Base.extend ModelHelpers
require 'passwordless/controller_helpers'
require "passwordless/controller_helpers"
end

config.before_initialize do |app|
app.config.i18n.load_path +=
Dir[Engine.root.join('config', 'locales', '*.yml')]
Dir[Engine.root.join("config", "locales", "*.yml")]
end
end
end
2 changes: 1 addition & 1 deletion lib/passwordless/model_helpers.rb
Expand Up @@ -9,7 +9,7 @@ module ModelHelpers
# @param field [string] email submitted by user.
def passwordless_with(field)
has_many :passwordless_sessions,
class_name: 'Passwordless::Session',
class_name: "Passwordless::Session",
as: :authenticatable

define_singleton_method(:passwordless_email_field) { field }
Expand Down
2 changes: 1 addition & 1 deletion lib/passwordless/router_helpers.rb
Expand Up @@ -21,7 +21,7 @@ def passwordless_for(resource, at: nil, as: nil)
mount_as = as || resource.to_s
mount(
Passwordless::Engine, at: mount_at, as: mount_as,
defaults: { authenticatable: resource.to_s.singularize }
defaults: {authenticatable: resource.to_s.singularize}
)

Passwordless.mounted_as = mount_as
Expand Down
2 changes: 1 addition & 1 deletion lib/passwordless/version.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Passwordless
VERSION = '0.6.0' # :nodoc:
VERSION = "0.6.0" # :nodoc:
end
4 changes: 2 additions & 2 deletions passwordless.gemspec
@@ -1,4 +1,4 @@
$:.push File.expand_path("../lib", __FILE__)
$LOAD_PATH.push File.expand_path("../lib", __FILE__)

# Maintain your gem's version:
require "passwordless/version"
Expand All @@ -21,5 +21,5 @@ Gem::Specification.new do |s|

s.add_development_dependency "sqlite3", "~> 1.3.6"
s.add_development_dependency "yard"
s.add_development_dependency "rubocop"
s.add_development_dependency "standard"
end