Skip to content
Permalink
Browse files

Convert code to standard style (#45)

  • Loading branch information...
mikker committed Feb 22, 2019
1 parent c2aa8c4 commit d76e229f54c504d3c63aa327000e86aaf82177a7
Showing with 220 additions and 257 deletions.
  1. +0 βˆ’37 .rubocop.yml
  2. +5 βˆ’0 .standard.yml
  3. +2 βˆ’2 Gemfile
  4. +1 βˆ’1 README.md
  5. +12 βˆ’10 Rakefile
  6. +2 βˆ’5 app/controllers/passwordless/sessions_controller.rb
  7. +2 βˆ’2 app/mailers/passwordless/mailer.rb
  8. +3 βˆ’3 app/models/passwordless/session.rb
  9. +4 βˆ’4 config/routes.rb
  10. +1 βˆ’1 db/migrate/20171104221735_create_passwordless_sessions.rb
  11. +3 βˆ’3 lib/passwordless.rb
  12. +3 βˆ’3 lib/passwordless/controller_helpers.rb
  13. +4 βˆ’4 lib/passwordless/engine.rb
  14. +1 βˆ’1 lib/passwordless/model_helpers.rb
  15. +1 βˆ’1 lib/passwordless/router_helpers.rb
  16. +1 βˆ’1 lib/passwordless/version.rb
  17. +2 βˆ’2 passwordless.gemspec
  18. +48 βˆ’48 test/controllers/passwordless/sessions_controller_test.rb
  19. +1 βˆ’1 test/dummy/Rakefile
  20. +1 βˆ’1 test/dummy/app/controllers/application_controller.rb
  21. +1 βˆ’1 test/dummy/app/controllers/secrets_controller.rb
  22. +2 βˆ’2 test/dummy/app/controllers/users_controller.rb
  23. +2 βˆ’2 test/dummy/app/mailers/application_mailer.rb
  24. +2 βˆ’2 test/dummy/bin/bundle
  25. +3 βˆ’3 test/dummy/bin/rails
  26. +2 βˆ’2 test/dummy/bin/rake
  27. +9 βˆ’9 test/dummy/bin/setup
  28. +9 βˆ’9 test/dummy/bin/update
  29. +6 βˆ’8 test/dummy/bin/yarn
  30. +1 βˆ’1 test/dummy/config.ru
  31. +9 βˆ’9 test/dummy/config/application.rb
  32. +3 βˆ’3 test/dummy/config/boot.rb
  33. +1 βˆ’1 test/dummy/config/environment.rb
  34. +2 βˆ’2 test/dummy/config/environments/development.rb
  35. +2 βˆ’2 test/dummy/config/environments/production.rb
  36. +1 βˆ’1 test/dummy/config/environments/test.rb
  37. +3 βˆ’3 test/dummy/config/puma.rb
  38. +2 βˆ’2 test/dummy/config/routes.rb
  39. +0 βˆ’2 test/dummy/db/schema.rb
  40. +13 βˆ’13 test/integration/navigation_test.rb
  41. +2 βˆ’2 test/models/authenticatable_test.rb
  42. +15 βˆ’15 test/models/passwordless/session_test.rb
  43. +21 βˆ’21 test/passwordless_for_test.rb
  44. +1 βˆ’1 test/passwordless_test.rb
  45. +2 βˆ’2 test/passwordless_with_test.rb
  46. +9 βˆ’9 test/test_helper.rb

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,5 @@
fix: true
parallel: true
ruby_version: 2.4
ignore:
- 'test/dummy/bin/*'
@@ -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
@@ -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.

@@ -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"
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'bcrypt'
require "bcrypt"

module Passwordless
# Controller for managing Passwordless sessions
@@ -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
@@ -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
@@ -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
@@ -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?
@@ -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
@@ -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
@@ -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
@@ -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 }
@@ -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
@@ -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

@@ -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
@@ -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
@@ -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 }
@@ -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
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Passwordless
VERSION = '0.6.0' # :nodoc:
VERSION = "0.6.0" # :nodoc:
end
@@ -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"
@@ -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
Oops, something went wrong.

0 comments on commit d76e229

Please sign in to comment.
You can’t perform that action at this time.