Permalink
Browse files

Corrected check on lkink options

  • Loading branch information...
donv committed Apr 6, 2017
1 parent 6104034 commit e62476090b6b2a7672b7cb33f7f7f36b15037333
View
@@ -13,12 +13,15 @@ AllCops:
Rails:
Enabled: true
Metrics/LineLength:
Max: 100
Style/AlignParameters:
EnforcedStyle: with_fixed_indentation
IndentationWidth: 4
Style/Encoding:
Enabled: true
Style/ClassAndModuleChildren:
Enabled: false
Style/SafeNavigation:
ConvertCodeThatCanStartToReturnNil: true
View
@@ -8,48 +8,17 @@
# Offense count: 6
Metrics/AbcSize:
Max: 53
Max: 56
# Offense count: 1
Metrics/CyclomaticComplexity:
Max: 11
# Offense count: 43
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Max: 142
# Offense count: 6
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 23
Max: 33
# Offense count: 1
Metrics/PerceivedComplexity:
Max: 11
# Offense count: 7
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: nested, compact
Style/ClassAndModuleChildren:
Exclude:
- 'lib/simple_workflow.rb'
- 'lib/simple_workflow/controller.rb'
- 'lib/simple_workflow/detour.rb'
- 'lib/simple_workflow/helper.rb'
- 'lib/simple_workflow/middleware.rb'
- 'lib/simple_workflow/test_helper.rb'
# Offense count: 9
Style/Documentation:
Exclude:
- 'spec/**/*'
- 'test/**/*'
- 'lib/simple_workflow.rb'
- 'lib/simple_workflow/controller.rb'
- 'lib/simple_workflow/detour.rb'
- 'lib/simple_workflow/helper.rb'
- 'lib/simple_workflow/middleware.rb'
- 'lib/simple_workflow/railtie.rb'
- 'lib/simple_workflow/test_helper.rb'
View
@@ -1,4 +1,5 @@
unless $LOAD_PATH.include?(File.dirname(__FILE__)) || $LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__)))
unless $LOAD_PATH.include?(File.dirname(__FILE__)) ||
$LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__)))
$LOAD_PATH.unshift(File.dirname(__FILE__))
end
@@ -11,15 +12,18 @@
require 'simple_workflow/middleware'
require 'simple_workflow/railtie'
# Make workflow test utility methods available in views
module ApplicationHelper
include SimpleWorkflow::Helper
end
# Make workflow test utility methods available in controllers
class ActionController::Base
include SimpleWorkflow::Helper
include SimpleWorkflow::Controller
end
# Make workflow test utility methods available in ActiveSupport test cases
class ActiveSupport::TestCase
include SimpleWorkflow::TestHelper
end
@@ -1,9 +1,11 @@
require 'simple_workflow/detour'
# Mixin to add controller methods for workflow navigation.
module SimpleWorkflow::Controller
include SimpleWorkflow::Detour
# Like ActionController::Base#redirect_to, but stores the location we come from, enabling returning here later.
# Like ActionController::Base#redirect_to, but stores the location we come from, enabling
# returning here later.
def detour_to(options)
store_detour(params)
redirect_to(options)
@@ -1,3 +1,4 @@
# Utility methods to manage the breadcrumb history
module SimpleWorkflow::Detour
def store_detour_in_session(session, options)
if session[:detours] && session[:detours].last == options
@@ -6,7 +7,8 @@ def store_detour_in_session(session, options)
end
session[:detours] ||= []
session[:detours] << options
Rails.logger.try(:debug, "Added detour (#{session[:detours].try(:size) || 0}): #{options.inspect}")
Rails.logger
.try(:debug, "Added detour (#{session[:detours].try(:size) || 0}): #{options.inspect}")
end
def pop_detour(session)
@@ -1,11 +1,15 @@
require_relative 'detour'
# View helper methods augmented with breadcrumb management.
module SimpleWorkflow::Helper
include SimpleWorkflow::Detour
def image_button_to(image_source, title, options, html_options = {})
image_submit_tag image_source, { class: 'image-submit', alt: title, title: title,
id: "#{title}_#{options[:id]}", name: title,
onclick: "form.action='#{url_for(options)}'" }.update(html_options)
image_submit_tag image_source, {
class: 'image-submit', alt: title, title: title,
id: "#{title}_#{options[:id]}", name: title,
onclick: "form.action='#{url_for(options)}'"
}.update(html_options)
end
def detour_to(title, options = nil, html_options = nil, &block)
@@ -56,7 +60,8 @@ def image_link_to(image_source, title, url_options, image_options = nil, link_op
link_to image_tag(image_source, image_options), url_options, link_options
end
def image_link_to_remote(image_source, title, link_options, image_options = nil, html_options = {})
def image_link_to_remote(image_source, title, link_options, image_options = nil,
html_options = {})
if html_options == true
html_options = { method: :post }
elsif html_options == false
@@ -84,7 +89,7 @@ def back_or_link_to(title, options = nil, html_options = nil)
link_options = options
end
link_to(title, link_options, html_options) if options
link_to(title, link_options, html_options) if link_options
rescue ActionController::UrlGenerationError => e
if session[:detours]
logger.error "Exception linking to origin: #{e.class} #{e}"
@@ -1,5 +1,6 @@
require 'simple_workflow/detour'
# Rack middleware to detect and store detours and manage returns from detours.
class SimpleWorkflow::Middleware
include SimpleWorkflow::Detour
@@ -38,7 +39,8 @@ def session(env)
end
def remove_old_detours(env)
return unless session(env).instance_variable_get('@by').is_a?(ActionDispatch::Session::CookieStore)
return unless session(env).instance_variable_get('@by')
.is_a?(ActionDispatch::Session::CookieStore)
session_size = workflow_size = nil
session = session(env)
# env[ActionDispatch::Cookies::COOKIES_SERIALIZER]
@@ -49,17 +51,26 @@ def remove_old_detours(env)
session_size = encryptor.encrypt_and_sign(ser_val).size
wf_ser_val = serialize_session(cookie_jar, session[:detours])
workflow_size = encryptor.encrypt_and_sign(wf_ser_val).size
break unless workflow_size >= 2048 || (session_size >= 3072 && session[:detours] && !session[:detours].empty?)
Rails.logger.warn "Workflow too large (#{workflow_size}/#{session_size}). Dropping oldest detour."
break unless workflow_size >= 2048 ||
(session_size >= 3072 && session[:detours] && !session[:detours].empty?)
Rails.logger.warn(
"Workflow too large (#{workflow_size}/#{session_size}). Dropping oldest detour."
)
session[:detours].shift
reset_workflow(session) if session[:detours].empty?
end
Rails.logger.debug "session: #{session_size} bytes, workflow(#{session[:detours].try(:size) || 0}): #{workflow_size} bytes"
Rails.logger.debug <<-MSG.strip_heredoc
session: #{session_size} bytes, workflow(#{session[:detours].try(:size) || 0}): #{workflow_size} bytes
MSG
return unless session_size > 4096
Rails.logger.warn "simple_workflow: session exceeds cookie size limit: #{session_size} bytes. Workflow empty! Not My Fault!"
Rails.logger.warn <<-MSG.strip_heredoc
simple_workflow: session exceeds cookie size limit: #{session_size} bytes. Workflow empty! Not My Fault!
MSG
Rails.logger.warn "simple_workflow: session: #{session.to_hash}"
return unless (old_flashes = session[:flash] && session[:flash]['discard'])
Rails.logger.warn "simple_workflow: found discarded flash entries: #{old_flashes}. Deleting them."
Rails.logger.warn <<-MSG.strip_heredoc
simple_workflow: found discarded flash entries: #{old_flashes}. Deleting them.
MSG
session[:flash]['flashes'] = session[:flash]['flashes'].except(*old_flashes)
Rails.logger.warn "simple_workflow: session: #{session.to_hash}"
end
@@ -1,8 +1,8 @@
module SimpleWorkflow
# Railtie to activate the middleware.
class Railtie < Rails::Railtie
initializer 'SimpleWorkflow.configure_rails_initialization' do |app|
app.middleware.insert_before ActionDispatch::Flash,
SimpleWorkflow::Middleware
app.middleware.insert_before ActionDispatch::Flash, SimpleWorkflow::Middleware
end
end
end
@@ -1,3 +1,4 @@
# Utility methods to ease testing.
module SimpleWorkflow::TestHelper
def add_stored_detour(location = { controller: :bogus, action: :location })
@request.session[:detours] = [location]
@@ -1,3 +1,3 @@
module SimpleWorkflow
VERSION = '1.3.2'.freeze
VERSION = '1.3.3'.freeze
end
View
@@ -10,12 +10,15 @@ Gem::Specification.new do |s|
s.email = 'uwe@kubosch.no'
s.summary = 'Add simple breadcrumbs "detour" workflow to Ruby On Rails.'
s.homepage = 'https://github.com/donv/simple_workflow'
s.description = 'Expands Ruby On Rails to allow simple breadcrumb detour workflows.'
s.description =
'Expands Ruby On Rails to allow simple breadcrumb detour workflows.'
s.rubyforge_project = 'donv/simple_workflow'
s.required_ruby_version = '~> 2.1'
s.licenses = %w[MIT]
s.files = FileList['[A-Z]*', 'lib/**/*', 'test/**/*'].to_a
s.add_runtime_dependency('rails', '>=4', '<5.1')
s.add_development_dependency('simplecov', '~>0.9')
s.add_development_dependency('minitest-reporters', '~>1.0')
s.add_development_dependency('rubocop', '~>0.45')
View
@@ -0,0 +1,4 @@
inherit_from: ../.rubocop.yml
Metrics/LineLength:
Max: 200

0 comments on commit e624760

Please sign in to comment.