Permalink
Browse files

directive crud done (#4)

* directive crud done

* double quotes FTL

* yaml

* quoutesgit

* updated to my houndci spec

* vioslations addressed
  • Loading branch information...
pedantix committed Jun 28, 2016
1 parent 2832ed0 commit bb5ede60067f473079bb2f6b2b9b102c80ef58d0
View
@@ -7,7 +7,7 @@ javascript:
enabled: true
# ignore_file: .javascript_ignore
ruby:
# config_file: .ruby-style.yml
config_file: .ruby-style.yml
enabled: true
scss:
# config_file: .scss-style.yml
View
@@ -0,0 +1,243 @@
AllCops:
Exclude:
- "vendor/**/*"
- "db/schema.rb"
UseCache: false
Style/CollectionMethods:
Description: Preferred collection methods.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#map-find-select-reduce-size
Enabled: true
PreferredMethods:
collect: map
collect!: map!
find: detect
find_all: select
reduce: inject
Style/DotPosition:
Description: Checks the position of the dot in multi-line method calls.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-multi-line-chains
Enabled: true
EnforcedStyle: trailing
SupportedStyles:
- leading
- trailing
Style/FileName:
Description: Use snake_case for source file names.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#snake-case-files
Enabled: false
Exclude: []
Style/GuardClause:
Description: Check for conditionals that can be replaced with guard clauses
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals
Enabled: false
MinBodyLength: 1
Style/IfUnlessModifier:
Description: Favor modifier if/unless usage when you have a single-line body.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier
Enabled: false
MaxLineLength: 80
Style/OptionHash:
Description: Don't use option hashes when you can use keyword arguments.
Enabled: false
Style/PercentLiteralDelimiters:
Description: Use `%`-literal delimiters consistently
StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-literal-braces
Enabled: false
PreferredDelimiters:
"%": "()"
"%i": "()"
"%q": "()"
"%Q": "()"
"%r": "{}"
"%s": "()"
"%w": "()"
"%W": "()"
"%x": "()"
Style/PredicateName:
Description: Check the names of predicate methods.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#bool-methods-qmark
Enabled: true
NamePrefix:
- is_
- has_
- have_
NamePrefixBlacklist:
- is_
Exclude:
- spec/**/*
Style/RaiseArgs:
Description: Checks the arguments passed to raise/fail.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#exception-class-messages
Enabled: false
EnforcedStyle: exploded
SupportedStyles:
- compact
- exploded
Style/SignalException:
Description: Checks for proper usage of fail and raise.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#fail-method
Enabled: false
EnforcedStyle: semantic
SupportedStyles:
- only_raise
- only_fail
- semantic
Style/SingleLineBlockParams:
Description: Enforces the names of some block params.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#reduce-blocks
Enabled: false
Methods:
- reduce:
- a
- e
- inject:
- a
- e
Style/SingleLineMethods:
Description: Avoid single-line methods.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-single-line-methods
Enabled: false
AllowIfMethodIsEmpty: true
Style/StringLiterals:
Description: Checks if uses of quotes match the configured preference.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-string-literals
Enabled: true
EnforcedStyle: double_quotes
SupportedStyles:
- single_quotes
- double_quotes
Style/StringLiteralsInInterpolation:
Description: Checks if uses of quotes inside expressions in interpolated strings
match the configured preference.
Enabled: true
EnforcedStyle: single_quotes
SupportedStyles:
- single_quotes
- double_quotes
Style/TrailingCommaInArguments:
Description: 'Checks for trailing comma in argument lists.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
Enabled: false
EnforcedStyleForMultiline: no_comma
SupportedStyles:
- comma
- consistent_comma
- no_comma
Style/TrailingCommaInLiteral:
Description: 'Checks for trailing comma in array and hash literals.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
Enabled: false
EnforcedStyleForMultiline: no_comma
SupportedStyles:
- comma
- consistent_comma
- no_comma
Metrics/AbcSize:
Description: A calculated magnitude based on number of assignments, branches, and
conditions.
Enabled: false
Max: 15
Metrics/ClassLength:
Description: Avoid classes longer than 100 lines of code.
Enabled: false
CountComments: false
Max: 100
Metrics/ModuleLength:
CountComments: false
Max: 100
Description: Avoid modules longer than 100 lines of code.
Enabled: false
Metrics/CyclomaticComplexity:
Description: A complexity metric that is strongly correlated to the number of test
cases needed to validate a method.
Enabled: false
Max: 6
Metrics/MethodLength:
Description: Avoid methods longer than 10 lines of code.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#short-methods
Enabled: false
CountComments: false
Max: 10
Metrics/ParameterLists:
Description: Avoid parameter lists longer than three or four parameters.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#too-many-params
Enabled: false
Max: 5
CountKeywordArgs: true
Metrics/PerceivedComplexity:
Description: A complexity metric geared towards measuring complexity for a human
reader.
Enabled: false
Max: 7
Lint/AssignmentInCondition:
Description: Don't use assignment in conditions.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#safe-assignment-in-condition
Enabled: false
AllowSafeAssignment: true
Style/InlineComment:
Description: Avoid inline comments.
Enabled: false
Style/AccessorMethodName:
Description: Check the naming of accessor methods for get_/set_.
Enabled: false
Style/Alias:
Description: Use alias_method instead of alias.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#alias-method
Enabled: false
Style/Documentation:
Description: Document classes and non-namespace modules.
Enabled: false
Style/DoubleNegation:
Description: Checks for uses of double negation (!!).
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-bang-bang
Enabled: false
Style/EachWithObject:
Description: Prefer `each_with_object` over `inject` or `reduce`.
Enabled: false
Style/EmptyLiteral:
Description: Prefer literals to Array.new/Hash.new/String.new.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#literal-array-hash
Enabled: false
Style/ModuleFunction:
Description: Checks for usage of `extend self` in modules.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#module-function
Enabled: false
Style/OneLineConditional:
Description: Favor the ternary operator(?:) over if/then/else/end constructs.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#ternary-operator
Enabled: false
Style/PerlBackrefs:
Description: Avoid Perl-style regex back references.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-perl-regexp-last-matchers
Enabled: false
Style/Send:
Description: Prefer `Object#__send__` or `Object#public_send` to `send`, as `send`
may overlap with existing methods.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#prefer-public-send
Enabled: false
Style/SpecialGlobalVars:
Description: Avoid Perl-style global variables.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-cryptic-perlisms
Enabled: false
Style/VariableInterpolation:
Description: Don't interpolate global, instance and class variables directly in
strings.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#curlies-interpolate
Enabled: false
Style/WhenThen:
Description: Use when x then ... for one-line cases.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#one-line-cases
Enabled: false
Lint/EachWithObjectArgument:
Description: Check for immutable argument given to each_with_object.
Enabled: true
Lint/HandleExceptions:
Description: Don't suppress exception.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#dont-hide-exceptions
Enabled: false
Lint/LiteralInCondition:
Description: Checks of literals used in conditions.
Enabled: false
Lint/LiteralInInterpolation:
Description: Checks for literals used in interpolation.
Enabled: false
View
@@ -41,6 +41,7 @@ group :development, :test do
gem "pry-byebug"
gem "pry-rails"
gem "rspec-rails", "~> 3.4.0"
gem 'rspec-retry'
end
group :development, :staging do
View
@@ -209,6 +209,8 @@ GEM
rspec-expectations (~> 3.4.0)
rspec-mocks (~> 3.4.0)
rspec-support (~> 3.4.0)
rspec-retry (0.4.5)
rspec-core
rspec-support (3.4.1)
safe_yaml (1.0.4)
sass (3.4.22)
@@ -309,6 +311,7 @@ DEPENDENCIES
rails_stdout_logging
recipient_interceptor
rspec-rails (~> 3.4.0)
rspec-retry
sass-rails (~> 5.0)
shoulda-matchers
simple_form
@@ -0,0 +1,51 @@
class DirectivesController < ApplicationController
helper_method :directive
before_action :authenticate_user!, except: :show
def show
end
def new
end
def edit
end
def create
user.create_directive!(directive_params)
flash[:success] = t(".success")
redirect_to root_path
rescue ActiveRecord::RecordInvalid
flash[:alert] = t(".failure")
render "new"
end
def update
directive.update! directive_params
flash[:success] = t(".success")
redirect_to root_path
rescue ActiveRecord::RecordInvalid
flash[:alert] = t(".failure")
render "edit"
end
def destroy
directive.destroy!
flash[:success] = t(".success")
redirect_to root_path
end
private
def directive_params
params.require(:directive).permit(:content)
end
def user
@user ||= User.find params[:user_id]
end
def directive
@directive ||= user.directive || user.build_directive
end
end
@@ -1,5 +1,9 @@
module FlashesHelper
def user_facing_flashes
flash.to_hash.slice("alert", "error", "notice", "success")
flash.to_hash.slice("alert", "error", "notice", "success", "secondary").
tap do |hash|
hash["primary"] = hash.delete "notice"
hash["warning"] = hash.delete "error"
end.compact
end
end
View
@@ -0,0 +1,4 @@
class Directive < ActiveRecord::Base
belongs_to :user
validates_presence_of :content
end
View
@@ -3,4 +3,10 @@ class User < ActiveRecord::Base
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
has_one :directive, dependent: :destroy
def has_directive?
directive.present?
end
end
@@ -1,6 +1,6 @@
<% if flash.any? %>
<% user_facing_flashes.each do |key, value| -%>
<div class="<%= key.to_s == 'notice' ? 'success' : 'alert' %> callout" data-closable>
<div class="<%= key.to_s %> callout" aria-label="Alert" data-closable>
<p><%= value %></p>
<button class="close-button"
aria-label="Dismiss alert"
@@ -0,0 +1,14 @@
<% content_error = directive.errors[:content].present? %>
<%= f.label :content,
class: (content_error ? "is-invalid-label" : nil) do %>
<%= t(".content") %>
<%= f.text_area :content, required: false, placeholder: t(".content_placeholder") %>
<% directive.errors.full_messages_for(:content).each do |mesage| %>
<%= content_tag :small, mesage , class: "form-error is-visible" %>
<% end %>
<% end %>
@@ -0,0 +1,9 @@
<div class="row">
<div class="medium-8 medium-centered columns">
<%= form_for(directive, url: user_directives_path(current_user), html: { method: :put }) do |f| %>
<h2 class="text-centered"><%= t(".title") %></h2>
<%= render 'form', f: f %>
<%= f.submit t(".submit"), class: "button expanded" %>
<% end %>
</div>
</div>
Oops, something went wrong.

0 comments on commit bb5ede6

Please sign in to comment.