├── .gitignore ├── .rubocop.yml ├── .ruby-style.yml ├── .travis.yml ├── Appraisals ├── CHANGELOG.md ├── CONTRIBUTING.md ├── Gemfile ├── Guardfile ├── MIT-LICENSE ├── README.md ├── Rakefile ├── active_waiter.gemspec ├── app ├── assets │ ├── images │ │ └── active_waiter │ │ │ └── .keep │ ├── javascripts │ │ └── active_waiter │ │ │ └── application.js │ └── stylesheets │ │ └── active_waiter │ │ └── application.css ├── controllers │ └── active_waiter │ │ ├── application_controller.rb │ │ └── jobs_controller.rb ├── helpers │ └── active_waiter │ │ └── application_helper.rb └── views │ ├── active_waiter │ └── jobs │ │ ├── _reload.html.erb │ │ ├── error.html.erb │ │ ├── link_to.html.erb │ │ ├── progress.html.erb │ │ └── show.html.erb │ └── layouts │ └── active_waiter │ └── application.html.erb ├── bin └── rails ├── config └── routes.rb ├── gemfiles ├── rails_4.2.gemfile ├── rails_5.0.gemfile └── rails_5.1.gemfile ├── lib ├── active_waiter.rb ├── active_waiter │ ├── configuration.rb │ ├── engine.rb │ ├── enumerable_job.rb │ ├── job.rb │ ├── store.rb │ └── version.rb └── tasks │ └── waiter_tasks.rake └── test ├── active_waiter ├── configuration_test.rb ├── enumerable_job_test.rb └── job_test.rb ├── controllers └── active_waiter │ └── jobs_controller_test.rb ├── dummy ├── README.rdoc ├── Rakefile ├── app │ ├── assets │ │ ├── images │ │ │ └── .keep │ │ ├── javascripts │ │ │ └── application.js │ │ └── stylesheets │ │ │ └── application.css │ ├── controllers │ │ ├── application_controller.rb │ │ └── concerns │ │ │ └── .keep │ ├── helpers │ │ └── application_helper.rb │ ├── mailers │ │ └── .keep │ ├── models │ │ ├── .keep │ │ └── concerns │ │ │ └── .keep │ └── views │ │ └── layouts │ │ └── application.html.erb ├── bin │ ├── bundle │ ├── rails │ ├── rake │ └── setup ├── config.ru ├── config │ ├── application.rb │ ├── boot.rb │ ├── environment.rb │ ├── environments │ │ ├── development.rb │ │ ├── production.rb │ │ └── test.rb │ ├── initializers │ │ ├── assets.rb │ │ ├── backtrace_silencers.rb │ │ ├── cookies_serializer.rb │ │ ├── filter_parameter_logging.rb │ │ ├── inflections.rb │ │ ├── mime_types.rb │ │ ├── session_store.rb │ │ └── wrap_parameters.rb │ ├── locales │ │ └── en.yml │ ├── routes.rb │ └── secrets.yml ├── lib │ └── assets │ │ └── .keep ├── log │ └── .keep └── public │ ├── 404.html │ ├── 422.html │ ├── 500.html │ └── favicon.ico ├── integration └── navigation_test.rb └── test_helper.rb /.gitignore: -------------------------------------------------------------------------------- 1 | .bundle/ 2 | log/*.log 3 | pkg/ 4 | test/dummy/db/*.sqlite3 5 | test/dummy/db/*.sqlite3-journal 6 | test/dummy/log/*.log 7 | test/dummy/tmp/ 8 | test/dummy/.sass-cache 9 | Gemfile.lock 10 | gemfiles/*.lock 11 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | inherit_from: 2 | - .ruby-style.yml 3 | -------------------------------------------------------------------------------- /.ruby-style.yml: -------------------------------------------------------------------------------- 1 | AllCops: 2 | Include: 3 | - "**/*.rake" 4 | - "**/Gemfile" 5 | - "**/Rakefile" 6 | 7 | RunRailsCops: true 8 | DisplayCopNames: false 9 | StyleGuideCopsOnly: false 10 | Style/AccessModifierIndentation: 11 | Description: Check indentation of private/protected visibility modifiers. 12 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#indent-public-private-protected 13 | Enabled: true 14 | EnforcedStyle: indent 15 | SupportedStyles: 16 | - outdent 17 | - indent 18 | Style/AlignHash: 19 | Description: Align the elements of a hash literal if they span more than one line. 20 | Enabled: true 21 | EnforcedHashRocketStyle: key 22 | EnforcedColonStyle: key 23 | EnforcedLastArgumentHashStyle: always_inspect 24 | SupportedLastArgumentHashStyles: 25 | - always_inspect 26 | - always_ignore 27 | - ignore_implicit 28 | - ignore_explicit 29 | Style/AlignParameters: 30 | Description: Align the parameters of a method call if they span more than one line. 31 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-double-indent 32 | Enabled: true 33 | EnforcedStyle: with_first_parameter 34 | SupportedStyles: 35 | - with_first_parameter 36 | - with_fixed_indentation 37 | Style/AndOr: 38 | Description: Use &&/|| instead of and/or. 39 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-and-or-or 40 | Enabled: true 41 | EnforcedStyle: always 42 | SupportedStyles: 43 | - always 44 | - conditionals 45 | Style/BarePercentLiterals: 46 | Description: Checks if usage of %() or %Q() matches configuration. 47 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-q-shorthand 48 | Enabled: true 49 | EnforcedStyle: bare_percent 50 | SupportedStyles: 51 | - percent_q 52 | - bare_percent 53 | Style/BracesAroundHashParameters: 54 | Description: Enforce braces style around hash parameters. 55 | Enabled: false 56 | EnforcedStyle: no_braces 57 | SupportedStyles: 58 | - braces 59 | - no_braces 60 | - context_dependent 61 | Style/CaseIndentation: 62 | Description: Indentation of when in a case/when/[else/]end. 63 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#indent-when-to-case 64 | Enabled: true 65 | IndentWhenRelativeTo: case 66 | SupportedStyles: 67 | - case 68 | - end 69 | IndentOneStep: false 70 | Style/ClassAndModuleChildren: 71 | Description: Checks style of children classes and modules. 72 | Enabled: false 73 | EnforcedStyle: nested 74 | SupportedStyles: 75 | - nested 76 | - compact 77 | Style/ClassCheck: 78 | Description: Enforces consistent use of `Object#is_a?` or `Object#kind_of?`. 79 | Enabled: true 80 | EnforcedStyle: is_a? 81 | SupportedStyles: 82 | - is_a? 83 | - kind_of? 84 | Style/CollectionMethods: 85 | Description: Preferred collection methods. 86 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#map-find-select-reduce-size 87 | Enabled: false 88 | PreferredMethods: 89 | collect: map 90 | collect!: map! 91 | inject: reduce 92 | detect: find 93 | find_all: select 94 | find: detect 95 | Style/CommentAnnotation: 96 | Description: Checks formatting of special comments (TODO, FIXME, OPTIMIZE, HACK, 97 | REVIEW). 98 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#annotate-keywords 99 | Enabled: false 100 | Keywords: 101 | - TODO 102 | - FIXME 103 | - OPTIMIZE 104 | - HACK 105 | - REVIEW 106 | Style/DotPosition: 107 | Description: Checks the position of the dot in multi-line method calls. 108 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-multi-line-chains 109 | Enabled: true 110 | EnforcedStyle: leading 111 | SupportedStyles: 112 | - leading 113 | - trailing 114 | Style/EmptyLineBetweenDefs: 115 | Description: Use empty lines between defs. 116 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#empty-lines-between-methods 117 | Enabled: true 118 | AllowAdjacentOneLineDefs: false 119 | Style/EmptyLinesAroundBlockBody: 120 | Description: Keeps track of empty lines around block bodies. 121 | Enabled: true 122 | EnforcedStyle: no_empty_lines 123 | SupportedStyles: 124 | - empty_lines 125 | - no_empty_lines 126 | Style/EmptyLinesAroundClassBody: 127 | Description: Keeps track of empty lines around class bodies. 128 | Enabled: true 129 | EnforcedStyle: no_empty_lines 130 | SupportedStyles: 131 | - empty_lines 132 | - no_empty_lines 133 | Style/EmptyLinesAroundModuleBody: 134 | Description: Keeps track of empty lines around module bodies. 135 | Enabled: true 136 | EnforcedStyle: no_empty_lines 137 | SupportedStyles: 138 | - empty_lines 139 | - no_empty_lines 140 | Style/Encoding: 141 | Description: Use UTF-8 as the source file encoding. 142 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#utf-8 143 | Enabled: false 144 | EnforcedStyle: always 145 | SupportedStyles: 146 | - when_needed 147 | - always 148 | Style/FileName: 149 | Description: Use snake_case for source file names. 150 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#snake-case-files 151 | Enabled: false 152 | Exclude: [] 153 | Style/FirstParameterIndentation: 154 | Description: Checks the indentation of the first parameter in a method call. 155 | Enabled: true 156 | EnforcedStyle: special_for_inner_method_call_in_parentheses 157 | SupportedStyles: 158 | - consistent 159 | - special_for_inner_method_call 160 | - special_for_inner_method_call_in_parentheses 161 | Style/For: 162 | Description: Checks use of for or each in multiline loops. 163 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-for-loops 164 | Enabled: true 165 | EnforcedStyle: each 166 | SupportedStyles: 167 | - for 168 | - each 169 | Style/FormatString: 170 | Description: Enforce the use of Kernel#sprintf, Kernel#format or String#%. 171 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#sprintf 172 | Enabled: false 173 | EnforcedStyle: format 174 | SupportedStyles: 175 | - format 176 | - sprintf 177 | - percent 178 | Style/GlobalVars: 179 | Description: Do not introduce global variables. 180 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#instance-vars 181 | Enabled: false 182 | AllowedVariables: [] 183 | Style/GuardClause: 184 | Description: Check for conditionals that can be replaced with guard clauses 185 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals 186 | Enabled: false 187 | MinBodyLength: 1 188 | Style/HashSyntax: 189 | Description: 'Prefer Ruby 1.9 hash syntax { a: 1, b: 2 } over 1.8 syntax { :a => 190 | 1, :b => 2 }.' 191 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#hash-literals 192 | Enabled: false 193 | EnforcedStyle: ruby19 194 | SupportedStyles: 195 | - ruby19 196 | - hash_rockets 197 | Style/IfUnlessModifier: 198 | Description: Favor modifier if/unless usage when you have a single-line body. 199 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier 200 | Enabled: false 201 | MaxLineLength: 80 202 | Style/IndentationWidth: 203 | Description: Use 2 spaces for indentation. 204 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#spaces-indentation 205 | Enabled: false 206 | Width: 2 207 | Style/IndentHash: 208 | Description: Checks the indentation of the first key in a hash literal. 209 | Enabled: false 210 | EnforcedStyle: special_inside_parentheses 211 | SupportedStyles: 212 | - special_inside_parentheses 213 | - consistent 214 | Style/LambdaCall: 215 | Description: Use lambda.call(...) instead of lambda.(...). 216 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#proc-call 217 | Enabled: false 218 | EnforcedStyle: call 219 | SupportedStyles: 220 | - call 221 | - braces 222 | Style/Next: 223 | Description: Use `next` to skip iteration instead of a condition at the end. 224 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals 225 | Enabled: false 226 | EnforcedStyle: skip_modifier_ifs 227 | MinBodyLength: 3 228 | SupportedStyles: 229 | - skip_modifier_ifs 230 | - always 231 | Style/NonNilCheck: 232 | Description: Checks for redundant nil checks. 233 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-non-nil-checks 234 | Enabled: true 235 | IncludeSemanticChanges: false 236 | Style/MethodDefParentheses: 237 | Description: Checks if the method definitions have or don't have parentheses. 238 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#method-parens 239 | Enabled: true 240 | EnforcedStyle: require_parentheses 241 | SupportedStyles: 242 | - require_parentheses 243 | - require_no_parentheses 244 | Style/MethodName: 245 | Description: Use the configured style when naming methods. 246 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#snake-case-symbols-methods-vars 247 | Enabled: true 248 | EnforcedStyle: snake_case 249 | SupportedStyles: 250 | - snake_case 251 | - camelCase 252 | Style/MultilineOperationIndentation: 253 | Description: Checks indentation of binary operations that span more than one line. 254 | Enabled: false 255 | EnforcedStyle: indented 256 | SupportedStyles: 257 | - aligned 258 | - indented 259 | Style/NumericLiterals: 260 | Description: Add underscores to large numeric literals to improve their readability. 261 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#underscores-in-numerics 262 | Enabled: false 263 | MinDigits: 5 264 | Style/ParenthesesAroundCondition: 265 | Description: Don't use parentheses around the condition of an if/unless/while. 266 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-parens-if 267 | Enabled: true 268 | AllowSafeAssignment: true 269 | Style/PercentLiteralDelimiters: 270 | Description: Use `%`-literal delimiters consistently 271 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-literal-braces 272 | Enabled: false 273 | PreferredDelimiters: 274 | "%": "()" 275 | "%i": "()" 276 | "%q": "()" 277 | "%Q": "()" 278 | "%r": "{}" 279 | "%s": "()" 280 | "%w": "()" 281 | "%W": "()" 282 | "%x": "()" 283 | Style/PercentQLiterals: 284 | Description: Checks if uses of %Q/%q match the configured preference. 285 | Enabled: true 286 | EnforcedStyle: lower_case_q 287 | SupportedStyles: 288 | - lower_case_q 289 | - upper_case_q 290 | Style/PredicateName: 291 | Description: Check the names of predicate methods. 292 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#bool-methods-qmark 293 | Enabled: true 294 | NamePrefix: 295 | - is_ 296 | - has_ 297 | - have_ 298 | NamePrefixBlacklist: 299 | - is_ 300 | Style/RaiseArgs: 301 | Description: Checks the arguments passed to raise/fail. 302 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#exception-class-messages 303 | Enabled: false 304 | EnforcedStyle: exploded 305 | SupportedStyles: 306 | - compact 307 | - exploded 308 | Style/RedundantReturn: 309 | Description: Don't use return where it's not required. 310 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-explicit-return 311 | Enabled: true 312 | AllowMultipleReturnValues: false 313 | Style/RegexpLiteral: 314 | Description: Use %r for regular expressions matching more than `MaxSlashes` '/' 315 | characters. Use %r only for regular expressions matching more than `MaxSlashes` 316 | '/' character. 317 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-r 318 | Enabled: false 319 | Style/Semicolon: 320 | Description: Don't use semicolons to terminate expressions. 321 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-semicolon 322 | Enabled: false 323 | AllowAsExpressionSeparator: false 324 | Style/SignalException: 325 | Description: Checks for proper usage of fail and raise. 326 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#fail-method 327 | Enabled: false 328 | EnforcedStyle: semantic 329 | SupportedStyles: 330 | - only_raise 331 | - only_fail 332 | - semantic 333 | Style/SingleLineBlockParams: 334 | Description: Enforces the names of some block params. 335 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#reduce-blocks 336 | Enabled: false 337 | Methods: 338 | - reduce: 339 | - a 340 | - e 341 | - inject: 342 | - a 343 | - e 344 | Style/SingleLineMethods: 345 | Description: Avoid single-line methods. 346 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-single-line-methods 347 | Enabled: false 348 | AllowIfMethodIsEmpty: true 349 | Style/StringLiterals: 350 | Description: Checks if uses of quotes match the configured preference. 351 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-string-literals 352 | Enabled: false 353 | EnforcedStyle: double_quotes 354 | SupportedStyles: 355 | - single_quotes 356 | - double_quotes 357 | Style/StringLiteralsInInterpolation: 358 | Description: Checks if uses of quotes inside expressions in interpolated strings 359 | match the configured preference. 360 | Enabled: true 361 | EnforcedStyle: single_quotes 362 | SupportedStyles: 363 | - single_quotes 364 | - double_quotes 365 | Style/SpaceAroundBlockParameters: 366 | Description: Checks the spacing inside and after block parameters pipes. 367 | Enabled: true 368 | EnforcedStyleInsidePipes: no_space 369 | SupportedStyles: 370 | - space 371 | - no_space 372 | Style/SpaceAroundEqualsInParameterDefault: 373 | Description: Checks that the equals signs in parameter default assignments have 374 | or don't have surrounding space depending on configuration. 375 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#spaces-around-equals 376 | Enabled: false 377 | EnforcedStyle: space 378 | SupportedStyles: 379 | - space 380 | - no_space 381 | Style/SpaceBeforeBlockBraces: 382 | Description: Checks that the left block brace has or doesn't have space before it. 383 | Enabled: true 384 | EnforcedStyle: space 385 | SupportedStyles: 386 | - space 387 | - no_space 388 | Style/SpaceInsideBlockBraces: 389 | Description: Checks that block braces have or don't have surrounding space. For 390 | blocks taking parameters, checks that the left brace has or doesn't have trailing 391 | space. 392 | Enabled: true 393 | EnforcedStyle: space 394 | SupportedStyles: 395 | - space 396 | - no_space 397 | EnforcedStyleForEmptyBraces: no_space 398 | SpaceBeforeBlockParameters: true 399 | Style/SpaceInsideHashLiteralBraces: 400 | Description: Use spaces inside hash literal braces - or don't. 401 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#spaces-operators 402 | Enabled: true 403 | EnforcedStyle: space 404 | EnforcedStyleForEmptyBraces: no_space 405 | SupportedStyles: 406 | - space 407 | - no_space 408 | Style/SymbolProc: 409 | Description: Use symbols as procs instead of blocks when possible. 410 | Enabled: true 411 | IgnoredMethods: 412 | - respond_to 413 | Style/TrailingBlankLines: 414 | Description: Checks trailing blank lines and final newline. 415 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#newline-eof 416 | Enabled: true 417 | EnforcedStyle: final_newline 418 | SupportedStyles: 419 | - final_newline 420 | - final_blank_line 421 | Style/TrailingComma: 422 | Description: Checks for trailing comma in parameter lists and literals. 423 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas 424 | Enabled: false 425 | EnforcedStyleForMultiline: no_comma 426 | SupportedStyles: 427 | - comma 428 | - no_comma 429 | Style/TrivialAccessors: 430 | Description: Prefer attr_* methods to trivial readers/writers. 431 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#attr_family 432 | Enabled: false 433 | ExactNameMatch: false 434 | AllowPredicates: false 435 | AllowDSLWriters: false 436 | Whitelist: 437 | - to_ary 438 | - to_a 439 | - to_c 440 | - to_enum 441 | - to_h 442 | - to_hash 443 | - to_i 444 | - to_int 445 | - to_io 446 | - to_open 447 | - to_path 448 | - to_proc 449 | - to_r 450 | - to_regexp 451 | - to_str 452 | - to_s 453 | - to_sym 454 | Style/VariableName: 455 | Description: Use the configured style when naming variables. 456 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#snake-case-symbols-methods-vars 457 | Enabled: true 458 | EnforcedStyle: snake_case 459 | SupportedStyles: 460 | - snake_case 461 | - camelCase 462 | Style/WhileUntilModifier: 463 | Description: Favor modifier while/until usage when you have a single-line body. 464 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#while-as-a-modifier 465 | Enabled: false 466 | MaxLineLength: 80 467 | Style/WordArray: 468 | Description: Use %w or %W for arrays of words. 469 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-w 470 | Enabled: false 471 | MinSize: 0 472 | WordRegex: !ruby/regexp /\A[\p{Word}]+\z/ 473 | Metrics/AbcSize: 474 | Description: A calculated magnitude based on number of assignments, branches, and 475 | conditions. 476 | Enabled: true 477 | Max: 50 478 | Metrics/BlockNesting: 479 | Description: Avoid excessive block nesting 480 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#three-is-the-number-thou-shalt-count 481 | Enabled: true 482 | Max: 3 483 | Metrics/ClassLength: 484 | Description: Avoid classes longer than 100 lines of code. 485 | Enabled: false 486 | CountComments: false 487 | Max: 100 488 | Metrics/CyclomaticComplexity: 489 | Description: A complexity metric that is strongly correlated to the number of test 490 | cases needed to validate a method. 491 | Enabled: false 492 | Max: 6 493 | Metrics/LineLength: 494 | Description: Limit lines to 80 characters. 495 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#80-character-limits 496 | Enabled: false 497 | Max: 80 498 | AllowURI: true 499 | URISchemes: 500 | - http 501 | - https 502 | Metrics/MethodLength: 503 | Description: Avoid methods longer than 10 lines of code. 504 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#short-methods 505 | Enabled: true 506 | CountComments: true 507 | Max: 40 508 | Exclude: 509 | - "spec/**/*" 510 | Metrics/ParameterLists: 511 | Description: Avoid long parameter lists. 512 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#too-many-params 513 | Enabled: false 514 | Max: 5 515 | CountKeywordArgs: true 516 | Metrics/PerceivedComplexity: 517 | Description: A complexity metric geared towards measuring complexity for a human 518 | reader. 519 | Enabled: false 520 | Max: 7 521 | Lint/AssignmentInCondition: 522 | Description: Don't use assignment in conditions. 523 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#safe-assignment-in-condition 524 | Enabled: false 525 | AllowSafeAssignment: true 526 | Lint/EndAlignment: 527 | Description: Align ends correctly. 528 | Enabled: false 529 | AlignWith: keyword 530 | SupportedStyles: 531 | - keyword 532 | - variable 533 | Lint/DefEndAlignment: 534 | Description: Align ends corresponding to defs correctly. 535 | Enabled: true 536 | AlignWith: start_of_line 537 | SupportedStyles: 538 | - start_of_line 539 | - def 540 | Rails/ActionFilter: 541 | Description: Enforces consistent use of action filter methods. 542 | Enabled: true 543 | EnforcedStyle: action 544 | SupportedStyles: 545 | - action 546 | - filter 547 | Include: 548 | - app/controllers/**/*.rb 549 | Rails/DefaultScope: 550 | Description: Checks if the argument passed to default_scope is a block. 551 | Enabled: true 552 | Include: 553 | - app/models/**/*.rb 554 | Rails/HasAndBelongsToMany: 555 | Description: Prefer has_many :through to has_and_belongs_to_many. 556 | Enabled: false 557 | Include: 558 | - app/models/**/*.rb 559 | Rails/Output: 560 | Description: Checks for calls to puts, print, etc. 561 | Enabled: true 562 | Include: 563 | - app/**/*.rb 564 | - config/**/*.rb 565 | - db/**/*.rb 566 | - lib/**/*.rb 567 | Rails/ReadWriteAttribute: 568 | Description: Checks for read_attribute(:attr) and write_attribute(:attr, val). 569 | Enabled: true 570 | Include: 571 | - app/models/**/*.rb 572 | Rails/ScopeArgs: 573 | Description: Checks the arguments of ActiveRecord scopes. 574 | Enabled: true 575 | Include: 576 | - app/models/**/*.rb 577 | Rails/Validation: 578 | Description: Use validates :attribute, hash of validations. 579 | Enabled: false 580 | Include: 581 | - app/models/**/*.rb 582 | Style/InlineComment: 583 | Description: Avoid inline comments. 584 | Enabled: false 585 | Style/MethodCalledOnDoEndBlock: 586 | Description: Avoid chaining a method call on a do...end block. 587 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#single-line-blocks 588 | Enabled: false 589 | Style/SymbolArray: 590 | Description: Use %i or %I for arrays of symbols. 591 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-i 592 | Enabled: false 593 | Style/ExtraSpacing: 594 | Description: Do not use unnecessary spacing. 595 | Enabled: false 596 | Style/AccessorMethodName: 597 | Description: Check the naming of accessor methods for get_/set_. 598 | Enabled: false 599 | Style/Alias: 600 | Description: Use alias_method instead of alias. 601 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#alias-method 602 | Enabled: false 603 | Style/AlignArray: 604 | Description: Align the elements of an array literal if they span more than one line. 605 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#align-multiline-arrays 606 | Enabled: true 607 | Style/ArrayJoin: 608 | Description: Use Array#join instead of Array#*. 609 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#array-join 610 | Enabled: false 611 | Style/AsciiComments: 612 | Description: Use only ascii symbols in comments. 613 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#english-comments 614 | Enabled: false 615 | Style/AsciiIdentifiers: 616 | Description: Use only ascii symbols in identifiers. 617 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#english-identifiers 618 | Enabled: false 619 | Style/Attr: 620 | Description: Checks for uses of Module#attr. 621 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#attr 622 | Enabled: false 623 | Style/BeginBlock: 624 | Description: Avoid the use of BEGIN blocks. 625 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-BEGIN-blocks 626 | Enabled: true 627 | Style/BlockComments: 628 | Description: Do not use block comments. 629 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-block-comments 630 | Enabled: true 631 | Style/BlockEndNewline: 632 | Description: Put end statement of multiline block on its own line. 633 | Enabled: true 634 | Style/Blocks: 635 | Description: Avoid using {...} for multi-line blocks. 636 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#single-line-blocks 637 | Enabled: false 638 | Style/CaseEquality: 639 | Description: Avoid explicit use of the case equality operator(===). 640 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-case-equality 641 | Enabled: false 642 | Style/CharacterLiteral: 643 | Description: Checks for uses of character literals. 644 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-character-literals 645 | Enabled: false 646 | Style/ClassAndModuleCamelCase: 647 | Description: Use CamelCase for classes and modules. 648 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#camelcase-classes 649 | Enabled: true 650 | Style/ClassMethods: 651 | Description: Use self when defining module/class methods. 652 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#def-self-singletons 653 | Enabled: true 654 | Style/ClassVars: 655 | Description: Avoid the use of class variables. 656 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-class-vars 657 | Enabled: false 658 | Style/ColonMethodCall: 659 | Description: 'Do not use :: for method call.' 660 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#double-colons 661 | Enabled: false 662 | Style/CommentIndentation: 663 | Description: Indentation of comments. 664 | Enabled: true 665 | Style/ConstantName: 666 | Description: Constants should use SCREAMING_SNAKE_CASE. 667 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#screaming-snake-case 668 | Enabled: true 669 | Style/DefWithParentheses: 670 | Description: Use def with parentheses when there are arguments. 671 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#method-parens 672 | Enabled: true 673 | Style/DeprecatedHashMethods: 674 | Description: Checks for use of deprecated Hash methods. 675 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#hash-key 676 | Enabled: false 677 | Style/Documentation: 678 | Description: Document classes and non-namespace modules. 679 | Enabled: false 680 | Style/DoubleNegation: 681 | Description: Checks for uses of double negation (!!). 682 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-bang-bang 683 | Enabled: false 684 | Style/EachWithObject: 685 | Description: Prefer `each_with_object` over `inject` or `reduce`. 686 | Enabled: false 687 | Style/ElseAlignment: 688 | Description: Align elses and elsifs correctly. 689 | Enabled: false 690 | Style/EmptyElse: 691 | Description: Avoid empty else-clauses. 692 | Enabled: false 693 | Style/EmptyLines: 694 | Description: Don't use several empty lines in a row. 695 | Enabled: true 696 | Style/EmptyLinesAroundAccessModifier: 697 | Description: Keep blank lines around access modifiers. 698 | Enabled: true 699 | Style/EmptyLinesAroundMethodBody: 700 | Description: Keeps track of empty lines around method bodies. 701 | Enabled: true 702 | Style/EmptyLiteral: 703 | Description: Prefer literals to Array.new/Hash.new/String.new. 704 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#literal-array-hash 705 | Enabled: false 706 | Style/EndBlock: 707 | Description: Avoid the use of END blocks. 708 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-END-blocks 709 | Enabled: true 710 | Style/EndOfLine: 711 | Description: Use Unix-style line endings. 712 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#crlf 713 | Enabled: true 714 | Style/EvenOdd: 715 | Description: Favor the use of Fixnum#even? && Fixnum#odd? 716 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#predicate-methods 717 | Enabled: false 718 | Style/FlipFlop: 719 | Description: Checks for flip flops 720 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-flip-flops 721 | Enabled: false 722 | Style/IfWithSemicolon: 723 | Description: Do not use if x; .... Use the ternary operator instead. 724 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-semicolon-ifs 725 | Enabled: false 726 | Style/IndentationConsistency: 727 | Description: Keep indentation straight. 728 | Enabled: false 729 | Style/IndentArray: 730 | Description: Checks the indentation of the first element in an array literal. 731 | Enabled: true 732 | Style/InfiniteLoop: 733 | Description: Use Kernel#loop for infinite loops. 734 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#infinite-loop 735 | Enabled: true 736 | Style/Lambda: 737 | Description: Use the new lambda literal syntax for single-line blocks. 738 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#lambda-multi-line 739 | Enabled: false 740 | Style/LeadingCommentSpace: 741 | Description: Comments should start with a space. 742 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#hash-space 743 | Enabled: true 744 | Style/LineEndConcatenation: 745 | Description: Use \ instead of + or << to concatenate two string literals at line 746 | end. 747 | Enabled: false 748 | Style/MethodCallParentheses: 749 | Description: Do not use parentheses for method calls with no arguments. 750 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-args-no-parens 751 | Enabled: true 752 | Style/ModuleFunction: 753 | Description: Checks for usage of `extend self` in modules. 754 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#module-function 755 | Enabled: false 756 | Style/MultilineBlockChain: 757 | Description: Avoid multi-line chains of blocks. 758 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#single-line-blocks 759 | Enabled: true 760 | Style/MultilineBlockLayout: 761 | Description: Ensures newlines after multiline block do statements. 762 | Enabled: true 763 | Style/MultilineIfThen: 764 | Description: Do not use then for multi-line if/unless. 765 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-then 766 | Enabled: true 767 | Style/MultilineTernaryOperator: 768 | Description: 'Avoid multi-line ?: (the ternary operator); use if/unless instead.' 769 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-multiline-ternary 770 | Enabled: true 771 | Style/NegatedIf: 772 | Description: Favor unless over if for negative conditions (or control flow or). 773 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#unless-for-negatives 774 | Enabled: false 775 | Style/NegatedWhile: 776 | Description: Favor until over while for negative conditions. 777 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#until-for-negatives 778 | Enabled: false 779 | Style/NestedTernaryOperator: 780 | Description: Use one expression per branch in a ternary operator. 781 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-nested-ternary 782 | Enabled: true 783 | Style/NilComparison: 784 | Description: Prefer x.nil? to x == nil. 785 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#predicate-methods 786 | Enabled: false 787 | Style/Not: 788 | Description: Use ! instead of not. 789 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#bang-not-not 790 | Enabled: false 791 | Style/OneLineConditional: 792 | Description: Favor the ternary operator(?:) over if/then/else/end constructs. 793 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#ternary-operator 794 | Enabled: false 795 | Style/OpMethod: 796 | Description: When defining binary operators, name the argument other. 797 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#other-arg 798 | Enabled: false 799 | Style/PerlBackrefs: 800 | Description: Avoid Perl-style regex back references. 801 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-perl-regexp-last-matchers 802 | Enabled: false 803 | Style/Proc: 804 | Description: Use proc instead of Proc.new. 805 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#proc 806 | Enabled: false 807 | Style/RedundantBegin: 808 | Description: Don't use begin blocks when they are not needed. 809 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#begin-implicit 810 | Enabled: true 811 | Style/RedundantException: 812 | Description: Checks for an obsolete RuntimeException argument in raise/fail. 813 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-explicit-runtimeerror 814 | Enabled: true 815 | Style/RedundantSelf: 816 | Description: Don't use self where it's not needed. 817 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-self-unless-required 818 | Enabled: true 819 | Style/RescueModifier: 820 | Description: Avoid using rescue in its modifier form. 821 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-rescue-modifiers 822 | Enabled: true 823 | Style/SelfAssignment: 824 | Description: Checks for places where self-assignment shorthand should have been 825 | used. 826 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#self-assignment 827 | Enabled: false 828 | Style/SingleSpaceBeforeFirstArg: 829 | Description: Checks that exactly one space is used between a method name and the 830 | first argument for method calls without parentheses. 831 | Enabled: false 832 | Style/SpaceAfterColon: 833 | Description: Use spaces after colons. 834 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#spaces-operators 835 | Enabled: true 836 | Style/SpaceAfterComma: 837 | Description: Use spaces after commas. 838 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#spaces-operators 839 | Enabled: true 840 | Style/SpaceAfterControlKeyword: 841 | Description: Use spaces after if/elsif/unless/while/until/case/when. 842 | Enabled: true 843 | Style/SpaceAfterMethodName: 844 | Description: Do not put a space between a method name and the opening parenthesis 845 | in a method definition. 846 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#parens-no-spaces 847 | Enabled: true 848 | Style/SpaceAfterNot: 849 | Description: Tracks redundant space after the ! operator. 850 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-space-bang 851 | Enabled: true 852 | Style/SpaceAfterSemicolon: 853 | Description: Use spaces after semicolons. 854 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#spaces-operators 855 | Enabled: true 856 | Style/SpaceBeforeComma: 857 | Description: No spaces before commas. 858 | Enabled: false 859 | Style/SpaceBeforeComment: 860 | Description: Checks for missing space between code and a comment on the same line. 861 | Enabled: true 862 | Style/SpaceBeforeSemicolon: 863 | Description: No spaces before semicolons. 864 | Enabled: true 865 | Style/SpaceAroundOperators: 866 | Description: Use spaces around operators. 867 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#spaces-operators 868 | Enabled: false 869 | Style/SpaceBeforeModifierKeyword: 870 | Description: Put a space before the modifier keyword. 871 | Enabled: true 872 | Style/SpaceInsideBrackets: 873 | Description: No spaces after [ or before ]. 874 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-spaces-braces 875 | Enabled: true 876 | Style/SpaceInsideParens: 877 | Description: No spaces after ( or before ). 878 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-spaces-braces 879 | Enabled: true 880 | Style/SpaceInsideRangeLiteral: 881 | Description: No spaces inside range literals. 882 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-space-inside-range-literals 883 | Enabled: true 884 | Style/SpecialGlobalVars: 885 | Description: Avoid Perl-style global variables. 886 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-cryptic-perlisms 887 | Enabled: false 888 | Style/StructInheritance: 889 | Description: Checks for inheritance from Struct.new. 890 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-extend-struct-new 891 | Enabled: true 892 | Style/Tab: 893 | Description: No hard tabs. 894 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#spaces-indentation 895 | Enabled: true 896 | Style/TrailingWhitespace: 897 | Description: Avoid trailing whitespace. 898 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-trailing-whitespace 899 | Enabled: true 900 | Style/UnlessElse: 901 | Description: Do not use unless with else. Rewrite these with the positive case first. 902 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-else-with-unless 903 | Enabled: true 904 | Style/UnneededCapitalW: 905 | Description: Checks for %W when interpolation is not needed. 906 | Enabled: true 907 | Style/UnneededPercentQ: 908 | Description: Checks for %q/%Q when single quotes or double quotes would do. 909 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-q 910 | Enabled: true 911 | Style/VariableInterpolation: 912 | Description: Don't interpolate global, instance and class variables directly in 913 | strings. 914 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#curlies-interpolate 915 | Enabled: false 916 | Style/WhenThen: 917 | Description: Use when x then ... for one-line cases. 918 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#one-line-cases 919 | Enabled: false 920 | Style/WhileUntilDo: 921 | Description: Checks for redundant do after while or until. 922 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-multiline-while-do 923 | Enabled: true 924 | Lint/AmbiguousOperator: 925 | Description: Checks for ambiguous operators in the first argument of a method invocation 926 | without parentheses. 927 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#parens-as-args 928 | Enabled: false 929 | Lint/AmbiguousRegexpLiteral: 930 | Description: Checks for ambiguous regexp literals in the first argument of a method 931 | invocation without parenthesis. 932 | Enabled: false 933 | Lint/BlockAlignment: 934 | Description: Align block ends correctly. 935 | Enabled: true 936 | Lint/ConditionPosition: 937 | Description: Checks for condition placed in a confusing position relative to the 938 | keyword. 939 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#same-line-condition 940 | Enabled: false 941 | Lint/Debugger: 942 | Description: Check for debugger calls. 943 | Enabled: true 944 | Lint/DeprecatedClassMethods: 945 | Description: Check for deprecated class method calls. 946 | Enabled: false 947 | Lint/DuplicateMethods: 948 | Description: Check for duplicate methods calls. 949 | Enabled: true 950 | Lint/ElseLayout: 951 | Description: Check for odd code arrangement in an else block. 952 | Enabled: false 953 | Lint/EmptyEnsure: 954 | Description: Checks for empty ensure block. 955 | Enabled: true 956 | Lint/EmptyInterpolation: 957 | Description: Checks for empty string interpolation. 958 | Enabled: true 959 | Lint/EndInMethod: 960 | Description: END blocks should not be placed inside method definitions. 961 | Enabled: true 962 | Lint/EnsureReturn: 963 | Description: Do not use return in an ensure block. 964 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-return-ensure 965 | Enabled: true 966 | Lint/Eval: 967 | Description: The use of eval represents a serious security risk. 968 | Enabled: true 969 | Lint/HandleExceptions: 970 | Description: Don't suppress exception. 971 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#dont-hide-exceptions 972 | Enabled: false 973 | Lint/InvalidCharacterLiteral: 974 | Description: Checks for invalid character literals with a non-escaped whitespace 975 | character. 976 | Enabled: false 977 | Lint/LiteralInCondition: 978 | Description: Checks of literals used in conditions. 979 | Enabled: false 980 | Lint/LiteralInInterpolation: 981 | Description: Checks for literals used in interpolation. 982 | Enabled: false 983 | Lint/Loop: 984 | Description: Use Kernel#loop with break rather than begin/end/until or begin/end/while 985 | for post-loop tests. 986 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#loop-with-break 987 | Enabled: false 988 | Lint/ParenthesesAsGroupedExpression: 989 | Description: Checks for method calls with a space before the opening parenthesis. 990 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#parens-no-spaces 991 | Enabled: false 992 | Lint/RequireParentheses: 993 | Description: Use parentheses in the method call to avoid confusion about precedence. 994 | Enabled: false 995 | Lint/RescueException: 996 | Description: Avoid rescuing the Exception class. 997 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-blind-rescues 998 | Enabled: true 999 | Lint/ShadowingOuterLocalVariable: 1000 | Description: Do not use the same name as outer local variable for block arguments 1001 | or block local variables. 1002 | Enabled: true 1003 | Lint/SpaceBeforeFirstArg: 1004 | Description: Put a space between a method name and the first argument in a method 1005 | call without parentheses. 1006 | Enabled: true 1007 | Lint/StringConversionInInterpolation: 1008 | Description: Checks for Object#to_s usage in string interpolation. 1009 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-to-s 1010 | Enabled: true 1011 | Lint/UnderscorePrefixedVariableName: 1012 | Description: Do not use prefix `_` for a variable that is used. 1013 | Enabled: false 1014 | Lint/UnusedBlockArgument: 1015 | Description: Checks for unused block arguments. 1016 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#underscore-unused-vars 1017 | Enabled: false 1018 | Lint/UnusedMethodArgument: 1019 | Description: Checks for unused method arguments. 1020 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#underscore-unused-vars 1021 | Enabled: true 1022 | Lint/UnreachableCode: 1023 | Description: Unreachable code. 1024 | Enabled: true 1025 | Lint/UselessAccessModifier: 1026 | Description: Checks for useless access modifiers. 1027 | Enabled: true 1028 | Lint/UselessAssignment: 1029 | Description: Checks for useless assignment to a local variable. 1030 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#underscore-unused-vars 1031 | Enabled: true 1032 | Lint/UselessComparison: 1033 | Description: Checks for comparison of something with itself. 1034 | Enabled: true 1035 | Lint/UselessElseWithoutRescue: 1036 | Description: Checks for useless `else` in `begin..end` without `rescue`. 1037 | Enabled: true 1038 | Lint/UselessSetterCall: 1039 | Description: Checks for useless setter call to a local variable. 1040 | Enabled: true 1041 | Lint/Void: 1042 | Description: Possible use of operator/literal/variable in void context. 1043 | Enabled: false 1044 | Rails/Delegate: 1045 | Description: Prefer delegate method for delegations. 1046 | Enabled: false 1047 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | bundler_args: --retry=3 --jobs=8 --no-deployment 3 | cache: bundler 4 | sudo: false 5 | rvm: 6 | - 2.2.5 7 | - 2.2.6 8 | - 2.3.0 9 | - 2.3.1 10 | - 2.3.2 11 | - 2.3.3 12 | - 2.4.1 13 | - ruby-head 14 | gemfile: 15 | - gemfiles/rails_5.1.gemfile 16 | - gemfiles/rails_5.0.gemfile 17 | - gemfiles/rails_4.2.gemfile 18 | matrix: 19 | allow_failures: 20 | - rvm: ruby-head 21 | fast_finish: true 22 | -------------------------------------------------------------------------------- /Appraisals: -------------------------------------------------------------------------------- 1 | [5.1, 5.0, 4.2].each do |version| 2 | appraise "rails-#{version}" do 3 | gem "rails", "~> #{version}.0" 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # CHANGELOG 2 | 3 | ## 0.3.4 4 | 5 | - Support Rails 5.1 6 | 7 | ## 0.3.0 8 | 9 | - Add ActiveWaiter::EnumerableJob as template for jobs that loop through resultset 10 | 11 | ## 0.2.0 - 2015.05.26 12 | 13 | - Support Ruby 2.0+ [PR#10](https://github.com/choonkeat/active_waiter/pull/10) 14 | 15 | - Add configuration option for layout [PR#1](https://github.com/choonkeat/active_waiter/pull/1/) 16 | 17 | ## 0.1.0 - 2015.05.24 18 | 19 | - Add toggle for download or redirect in controller/view [0dc1f1](https://github.com/choonkeat/active_waiter/commit/0dc1f1eea6ec6bb9fc5632ce976855d668ad423a) 20 | 21 | ## 0.0.1 - 2015.05.24 22 | 23 | - active waiter init 24 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contributing 2 | 3 | ### Development 4 | 5 | Run `bundle` to install development dependencies. 6 | 7 | #### Running Tests 8 | 9 | ``` 10 | $ rake 11 | ``` 12 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gemspec 4 | -------------------------------------------------------------------------------- /Guardfile: -------------------------------------------------------------------------------- 1 | # A sample Guardfile 2 | # More info at https://github.com/guard/guard#readme 3 | 4 | ## Uncomment and set this to only include directories you want to watch 5 | # directories %w(app lib config test spec features) 6 | 7 | ## Uncomment to clear the screen before every task 8 | # clearing :on 9 | 10 | ## Guard internally checks for changes in the Guardfile and exits. 11 | ## If you want Guard to automatically start up again, run guard in a 12 | ## shell loop, e.g.: 13 | ## 14 | ## $ while bundle exec guard; do echo "Restarting Guard..."; done 15 | ## 16 | ## Note: if you are using the `directories` clause above and you are not 17 | ## watching the project directory ('.'), then you will want to move 18 | ## the Guardfile to a watched dir and symlink it back, e.g. 19 | # 20 | # $ mkdir config 21 | # $ mv Guardfile config/ 22 | # $ ln -s config/Guardfile . 23 | # 24 | # and, you'll have to watch "config/Guardfile" instead of "Guardfile" 25 | 26 | guard :minitest do 27 | # with Minitest::Unit 28 | watch(%r{^test/(.*)\/?(.*)_test\.rb$}) 29 | watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}#{m[2]}_test.rb" } 30 | watch(%r{^test/test_helper\.rb$}) { 'test' } 31 | 32 | # with Minitest::Spec 33 | # watch(%r{^spec/(.*)_spec\.rb$}) 34 | # watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } 35 | # watch(%r{^spec/spec_helper\.rb$}) { 'spec' } 36 | 37 | # Rails 4 38 | # watch(%r{^app/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" } 39 | # watch(%r{^app/controllers/application_controller\.rb$}) { 'test/controllers' } 40 | watch(%r{^app/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}#{m[2]}_test.rb" } 41 | # watch(%r{^app/views/(.+)_mailer/.+}) { |m| "test/mailers/#{m[1]}_mailer_test.rb" } 42 | # watch(%r{^lib/(.+)\.rb$}) { |m| "test/lib/#{m[1]}_test.rb" } 43 | # watch(%r{^test/.+_test\.rb$}) 44 | # watch(%r{^test/test_helper\.rb$}) { 'test' } 45 | 46 | # Rails < 4 47 | # watch(%r{^app/controllers/(.*)\.rb$}) { |m| "test/functional/#{m[1]}_test.rb" } 48 | # watch(%r{^app/helpers/(.*)\.rb$}) { |m| "test/helpers/#{m[1]}_test.rb" } 49 | # watch(%r{^app/models/(.*)\.rb$}) { |m| "test/unit/#{m[1]}_test.rb" } 50 | 51 | callback(:start_begin) { `bundle exec rubocop -DR --auto-correct` } 52 | end 53 | -------------------------------------------------------------------------------- /MIT-LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2015 choonkeat 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ActiveWaiter 2 | 3 | [](https://travis-ci.org/choonkeat/active_waiter) 4 | 5 | A simple mechanism allowing your users to wait for the completion of your `ActiveJob` 6 | 7 | ## Scenario 8 | 9 | You have an export PDF feature that you've implemented directly in the controller action. 10 | 11 | As data grows, your HTTP request takes longer and starts timing out. So you decide to move the PDF generating code into a background job. 12 | 13 | ``` ruby 14 | def index 15 | respond_to do |format| 16 | format.html 17 | format.pdf { 18 | ExportPdfJob.perform_later(@things, current_user) 19 | redirect_to :back, notice: "We'll email your PDF when it's done!" 20 | } 21 | end 22 | end 23 | ``` 24 | 25 | But how do you get that PDF into the hands of your users now? Email? Push notification? Manual reload? 26 | 27 | > You have no PDF ready for download (yet). Please reload. 28 | 29 | 30 | ## Solution 31 | 32 | Let `ActiveWaiter` enqueue that job instead and redirect to its progress tracking page. 33 | 34 | ``` ruby 35 | def index 36 | respond_to do |format| 37 | format.html 38 | format.pdf { 39 | uid = ActiveWaiter.enqueue(ExportPdfJob, @things, current_user) 40 | redirect_to active_waiter_path(id: uid) 41 | } 42 | end 43 | end 44 | ``` 45 | 46 | ``` ruby 47 | # routes.rb 48 | mount ActiveWaiter::Engine => "/active_waiter" 49 | ``` 50 | 51 | When the job completes, the user will be redirected to the `url` returned by the job. However, if you want the user to be presented with a download link, add `download: 1` params instead 52 | 53 | ``` ruby 54 | redirect_to active_waiter_path(id: uid, download: 1) 55 | ``` 56 | 57 |  58 | 59 | And we need to add a bit of code into your `ActiveJob` class 60 | 61 | - 1) add `include ActiveWaiter::Job` 62 | - 2) return a `url` from your `perform` method to link to the result page (or file) 63 | 64 | ``` ruby 65 | class ExportPdfJob < ActiveJob::Base 66 | queue_as :default 67 | 68 | # (1) 69 | include ActiveWaiter::Job 70 | 71 | def perform(things, current_user) 72 | count = things.count.to_f 73 | files = [] 74 | things.each_with_index do |thing, index| 75 | files << generate_pdf(thing) 76 | 77 | # (a) 78 | update_active_waiter percentage: (100 * (index+1) / count) 79 | end 80 | 81 | # (2) 82 | upload(combine(files)).s3_url 83 | rescue Exception => e 84 | 85 | # (b) 86 | update_active_waiter error: e.to_s 87 | end 88 | end 89 | ``` 90 | 91 | Optionally, you can also 92 | 93 | - a) report progress while your job runs, using `update_active_waiter(percentage:)` 94 | - b) report if there were any errors, using `update_active_waiter(error:)` 95 | 96 | ### Configuration 97 | 98 | By default, `ActiveWaiter` uses a simple Bootstrap layout. To use your application's layout, configure: 99 | 100 | ```ruby 101 | ActiveWaiter.configure do |config| 102 | config.layout = "layouts/application" 103 | end 104 | ``` 105 | 106 | Next, prefix any routes used in your application's layout with `main_app.`, e.g. `main_app.sign_in_path`. 107 | 108 | This is required because `ActiveWaiter` is a Rails Engine mounted into your application, 109 | and it doesn't know about the routes declared within your application. 110 | 111 | #### Changing the shared cache 112 | 113 | For deploying in production environments, `ActiveWaiter` requires a shared cache to 114 | track the status of downloads. By default it uses the Rails cache. If you want to 115 | use something else other than the Rails cache like redis for example, you may specify 116 | your own implementation: 117 | 118 | ```ruby 119 | class RedisStore 120 | def write(uid, value) 121 | $redis.set("active_waiter:#{uid}", value) 122 | end 123 | 124 | def read(uid) 125 | $redis.get("active_waiter:#{uid}") 126 | end 127 | end 128 | 129 | ActiveWaiter.configure do |config| 130 | config.store = RedisStore.new 131 | end 132 | ``` 133 | 134 | #### Exceptions 135 | 136 | When your job gets an exception, the error message will be written in the error message and passed along 137 | to the user. If your job has a method `suppress_exceptions` that returns a truthy value (default false), 138 | `ActiveWaiter::Job` will swallow the exception and not raise it - this means there will be no retry by 139 | `ActiveJob`. 140 | 141 | ### Common Jobs 142 | 143 | #### ActiveWaiter::EnumerableJob 144 | 145 | If you need to wait, you're likely doing one thing slowly or many things. For the latter case, you can just 146 | `include ActiveWaiter::EnumerableJob` and add a few interface methods 147 | 148 | ``` ruby 149 | def before(*args); end # called once with arguments of `perform` 150 | def enumerable; [] end # an Enumerable interface 151 | def items_count; 1 end # called 0-n times, depending on enumerable 152 | def foreach(item); end # called 0-n times, depending on enumerable 153 | def after; end # called once 154 | def result; end # called once 155 | ``` 156 | 157 | Here's an example from our test code, that will generate an array of range `0...count` and return the sum 158 | of all the numbers 159 | 160 | ``` ruby 161 | class LoopJob < ActiveJob::Base 162 | include ActiveWaiter::EnumerableJob 163 | 164 | attr_accessor :items_count, :enumerable, :result 165 | 166 | def before(count) 167 | @items_count = count 168 | @enumerable = count.times 169 | @result = 0 170 | end 171 | 172 | def foreach(item) 173 | @result += item 174 | end 175 | end 176 | ``` 177 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env rake 2 | require "rubygems" 3 | require "bundler/setup" 4 | require "bundler/gem_tasks" 5 | require "rake/testtask" 6 | 7 | Rake::TestTask.new do |t| 8 | t.libs << "test" 9 | t.test_files = FileList['test/**/*_test.rb'] 10 | t.verbose = true 11 | end 12 | 13 | task default: :test 14 | -------------------------------------------------------------------------------- /active_waiter.gemspec: -------------------------------------------------------------------------------- 1 | $:.push File.expand_path("../lib", __FILE__) 2 | 3 | # Maintain your gem's version: 4 | require "active_waiter/version" 5 | 6 | # Describe your gem and declare its dependencies: 7 | Gem::Specification.new do |s| 8 | s.name = "active_waiter" 9 | s.version = ActiveWaiter::VERSION 10 | s.authors = ["choonkeat"] 11 | s.email = ["choonkeat@gmail.com"] 12 | s.homepage = "https://github.com/choonkeat/active_waiter" 13 | s.summary = "ActiveWaiter for background jobs to finish" 14 | s.description = "A simple mechanism allowing your users to wait for the completion of your `ActiveJob`" 15 | s.license = "MIT" 16 | 17 | s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"] 18 | 19 | s.required_ruby_version = "~> 2.0" 20 | 21 | s.add_dependency "rails", ">= 4.2" 22 | 23 | s.add_development_dependency "guard" 24 | s.add_development_dependency "guard-minitest" 25 | s.add_development_dependency "rubocop" 26 | s.add_development_dependency "rails-controller-testing" 27 | s.add_development_dependency "appraisal" 28 | end 29 | -------------------------------------------------------------------------------- /app/assets/images/active_waiter/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/choonkeat/active_waiter/5d6c82173eff6fcf2bd8bd1c28c6539b9989c2d1/app/assets/images/active_waiter/.keep -------------------------------------------------------------------------------- /app/assets/javascripts/active_waiter/application.js: -------------------------------------------------------------------------------- 1 | // This is a manifest file that'll be compiled into application.js, which will include all the files 2 | // listed below. 3 | // 4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, 5 | // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path. 6 | // 7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 8 | // compiled file. 9 | // 10 | // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details 11 | // about supported directives. 12 | // 13 | //= require_tree . 14 | -------------------------------------------------------------------------------- /app/assets/stylesheets/active_waiter/application.css: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a manifest file that'll be compiled into application.css, which will include all the files 3 | * listed below. 4 | * 5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, 6 | * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path. 7 | * 8 | * You're free to add application-wide styles to this file and they'll appear at the bottom of the 9 | * compiled file so the styles you add here take precedence over styles defined in any styles 10 | * defined in the other CSS/SCSS files in this directory. It is generally better to create a new 11 | * file per style scope. 12 | * 13 | *= require_tree . 14 | *= require_self 15 | */ 16 | -------------------------------------------------------------------------------- /app/controllers/active_waiter/application_controller.rb: -------------------------------------------------------------------------------- 1 | module ActiveWaiter 2 | class ApplicationController < ActionController::Base 3 | layout :active_waiter_layout 4 | 5 | private 6 | 7 | def active_waiter_layout 8 | ActiveWaiter.configuration.layout 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /app/controllers/active_waiter/jobs_controller.rb: -------------------------------------------------------------------------------- 1 | require_dependency "active_waiter/application_controller" 2 | 3 | module ActiveWaiter 4 | class JobsController < ApplicationController 5 | def show 6 | @retries = nil 7 | data = ActiveWaiter.read(params[:id]) 8 | return on_not_found(data) unless data.respond_to?(:[]) 9 | return on_error(data) if data[:error] 10 | return on_link_to(data) if data[:link_to] && params[:download] 11 | return on_redirect(data) if data[:link_to] 12 | return on_progress(data) if data[:percentage] 13 | end 14 | 15 | protected 16 | 17 | def on_not_found(_data) 18 | case retries = params[:retries].to_i 19 | when 0..9 20 | @retries = retries + 1 21 | else 22 | raise ActionController::RoutingError.new('Not Found') 23 | end 24 | end 25 | 26 | def on_error(data) 27 | render template: "active_waiter/jobs/error", status: :internal_server_error, locals: data 28 | end 29 | 30 | def on_redirect(data) 31 | redirect_to data[:link_to] 32 | end 33 | 34 | def on_link_to(data) 35 | render template: "active_waiter/jobs/link_to", locals: data 36 | end 37 | 38 | def on_progress(data) 39 | render template: "active_waiter/jobs/progress", locals: data 40 | end 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /app/helpers/active_waiter/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ActiveWaiter 2 | module ApplicationHelper 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /app/views/active_waiter/jobs/_reload.html.erb: -------------------------------------------------------------------------------- 1 | 4 | -------------------------------------------------------------------------------- /app/views/active_waiter/jobs/error.html.erb: -------------------------------------------------------------------------------- 1 |
7 | 8 | Click to 9 | Download 10 | 11 | 12 |
13 | -------------------------------------------------------------------------------- /app/views/active_waiter/jobs/progress.html.erb: -------------------------------------------------------------------------------- 1 |
You may have mistyped the address or the page may have moved.
63 |If you are the application owner check the logs for more information.
65 |Maybe you tried to change something you didn't have access to.
63 |If you are the application owner check the logs for more information.
65 |If you are the application owner check the logs for more information.
64 |