Skip to content

Commit f17ce76

Browse files
committed
Updates from standardrb
1 parent 3d5a1a7 commit f17ce76

16 files changed

+127
-126
lines changed

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
source "https://rubygems.org"
22

3-
gem 'rake'
3+
gem "rake"
44

55
gemspec

decent_exposure.gemspec

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
require File.expand_path("../lib/decent_exposure/version", __FILE__)
22

33
Gem::Specification.new do |spec|
4-
spec.name = "decent_exposure"
5-
spec.version = DecentExposure::VERSION
6-
spec.authors = ["Pavel Pravosud", "Stephen Caudill"]
7-
spec.email = ["[email protected]"]
8-
spec.summary = "A helper for creating declarative interfaces in controllers"
9-
spec.description = %q{
4+
spec.name = "decent_exposure"
5+
spec.version = DecentExposure::VERSION
6+
spec.authors = ["Pavel Pravosud", "Stephen Caudill"]
7+
spec.email = ["[email protected]"]
8+
spec.summary = "A helper for creating declarative interfaces in controllers"
9+
spec.description = '
1010
DecentExposure helps you program to an interface, rather than an
1111
implementation in your Rails controllers. The fact of the matter is that
1212
sharing state via instance variables in controllers promotes close coupling
1313
with views. DecentExposure gives you a declarative manner of exposing an
1414
interface to the state that controllers contain and thereby decreasing
1515
coupling and improving your testability and overall design.
16-
}
17-
spec.homepage = "https://github.com/hashrocket/decent_exposure"
18-
spec.license = "MIT"
19-
spec.files = `git ls-files -z`.split("\x0")
20-
spec.test_files = spec.files.grep(/\Aspec\//)
16+
'
17+
spec.homepage = "https://github.com/hashrocket/decent_exposure"
18+
spec.license = "MIT"
19+
spec.files = `git ls-files -z`.split("\x0")
20+
spec.test_files = spec.files.grep(/\Aspec\//)
2121
spec.require_path = "lib"
2222

2323
spec.required_ruby_version = "~> 2.0"
@@ -26,4 +26,5 @@ Gem::Specification.new do |spec|
2626
spec.add_development_dependency "railties", ">= 4.0"
2727
spec.add_development_dependency "actionmailer"
2828
spec.add_development_dependency "rspec-rails", "~> 3.0"
29+
spec.add_development_dependency "standard"
2930
end

lib/decent_exposure.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
module DecentExposure
66
autoload :Controller, "decent_exposure/controller"
7-
autoload :Mailer, "decent_exposure/mailer"
8-
autoload :Exposure, "decent_exposure/exposure"
9-
autoload :Attribute, "decent_exposure/attribute"
10-
autoload :Context, "decent_exposure/context"
11-
autoload :Behavior, "decent_exposure/behavior"
12-
autoload :Flow, "decent_exposure/flow"
7+
autoload :Mailer, "decent_exposure/mailer"
8+
autoload :Exposure, "decent_exposure/exposure"
9+
autoload :Attribute, "decent_exposure/attribute"
10+
autoload :Context, "decent_exposure/context"
11+
autoload :Behavior, "decent_exposure/behavior"
12+
autoload :Flow, "decent_exposure/flow"
1313

1414
ActiveSupport.on_load :action_controller do
1515
include Controller

lib/decent_exposure/attribute.rb

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ def setter_method_name
3232
"#{name}=".to_sym
3333
end
3434

35-
3635
# Public: Expose a getter and setter method for the Attribute
3736
# on the passed in Controller class.
3837
#

lib/decent_exposure/behavior.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def build_params
8686
protected
8787

8888
def params_id_key_candidates
89-
[ "#{model_param_key}_id", "#{name}_id", "id" ].uniq
89+
["#{model_param_key}_id", "#{name}_id", "id"].uniq
9090
end
9191

9292
def model_param_key

lib/decent_exposure/context.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def initialize(context, attribute)
2020
#
2121
# Returns the attribute's value.
2222
def get
23-
ivar_defined?? ivar_get : set(fetch_value)
23+
ivar_defined? ? ivar_get : set(fetch_value)
2424
end
2525

2626
# Public: Write to an attribute on the context Class.
@@ -51,7 +51,7 @@ def ivar_set(value)
5151
end
5252

5353
def ivar_name
54-
"@#{attribute.ivar_name.gsub('?', '_question_mark_')}"
54+
"@#{attribute.ivar_name.gsub("?", "_question_mark_")}"
5555
end
5656

5757
def fetch_value

lib/decent_exposure/exposure.rb

+17-17
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def self.expose!(*args, &block)
3434
# the Proc.
3535
#
3636
# Returns a normalized options Hash.
37-
def initialize(controller, name, fetch_block=nil, **options, &block)
37+
def initialize(controller, name, fetch_block = nil, **options, &block)
3838
@controller = controller
3939
@options = options.with_indifferent_access.merge(name: name)
4040

@@ -86,43 +86,43 @@ def normalize_options
8686

8787
def normalize_fetch_option
8888
normalize_non_proc_option :fetch do |method_name|
89-
->{ send(method_name) }
89+
-> { send(method_name) }
9090
end
9191
end
9292

9393
def normalize_find_by_option
94-
if find_by = options.delete(:find_by)
95-
merge_lambda_option :find, ->(id, scope){ scope.find_by!(find_by => id) }
94+
if (find_by = options.delete(:find_by))
95+
merge_lambda_option :find, ->(id, scope) { scope.find_by!(find_by => id) }
9696
end
9797
end
9898

9999
def normalize_parent_option
100100
exposure_name = options.fetch(:name)
101101

102-
if parent = options.delete(:parent)
103-
merge_lambda_option :scope, ->{ send(parent).send(exposure_name.to_s.pluralize) }
102+
if (parent = options.delete(:parent))
103+
merge_lambda_option :scope, -> { send(parent).send(exposure_name.to_s.pluralize) }
104104
end
105105
end
106106

107107
def normalize_from_option
108108
exposure_name = options.fetch(:name)
109109

110-
if from = options.delete(:from)
111-
merge_lambda_option :build, ->{ send(from).send(exposure_name) }
112-
merge_lambda_option :model, ->{ nil }
113-
merge_lambda_option :id, ->{ nil }
110+
if (from = options.delete(:from))
111+
merge_lambda_option :build, -> { send(from).send(exposure_name) }
112+
merge_lambda_option :model, -> { nil }
113+
merge_lambda_option :id, -> { nil }
114114
end
115115
end
116116

117117
def normalize_with_option
118-
if configs = options.delete(:with)
119-
Array.wrap(configs).each{ |config| reverse_merge_config! config }
118+
if (configs = options.delete(:with))
119+
Array.wrap(configs).each { |config| reverse_merge_config! config }
120120
end
121121
end
122122

123123
def normalize_id_option
124124
normalize_non_proc_option :id do |ids|
125-
->{ Array.wrap(ids).map{ |id| params[id] }.find(&:present?) }
125+
-> { Array.wrap(ids).map { |id| params[id] }.find(&:present?) }
126126
end
127127
end
128128

@@ -134,7 +134,7 @@ def normalize_model_option
134134
value
135135
end
136136

137-
->{ model }
137+
-> { model }
138138
end
139139
end
140140

@@ -147,7 +147,7 @@ def normalize_build_params_option
147147

148148
def normalize_scope_options
149149
normalize_non_proc_option :scope do |custom_scope|
150-
->(model){ model.send(custom_scope) }
150+
->(model) { model.send(custom_scope) }
151151
end
152152
end
153153

@@ -165,7 +165,7 @@ def normalize_non_proc_option(name)
165165
end
166166

167167
def merge_lambda_option(name, body)
168-
if previous_value = options[name] and Proc === previous_value
168+
if (previous_value = options[name]) && (Proc === previous_value)
169169
fail ArgumentError, "#{name.to_s.titleize} block is already defined"
170170
end
171171

@@ -178,7 +178,7 @@ def attribute
178178

179179
name = options.fetch(:name)
180180
ivar_name = "exposed_#{name}"
181-
fetch = ->{ Flow.new(self, local_options).fetch }
181+
fetch = -> { Flow.new(self, local_options).fetch }
182182

183183
Attribute.new(
184184
name: name,

lib/decent_exposure/flow.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def get_request?
4646
end
4747

4848
def params_method_name
49-
options.fetch(:build_params_method){ "#{name}_params" }
49+
options.fetch(:build_params_method) { "#{name}_params" }
5050
end
5151

5252
def handle_flow_method(name, *args, &block)
@@ -75,7 +75,6 @@ def handle_default_flow_method(name, *args, &block)
7575
method.bind(self).call(*args, &block)
7676
end
7777

78-
7978
def fetch_ivar(name)
8079
ivar_name = "@#{name}"
8180

lib/decent_exposure/mailer.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def self.included(base)
66

77
def process_action(*args)
88
arg = args.second
9-
self.params = arg.stringify_keys() if arg && Hash === arg
9+
self.params = arg.stringify_keys if arg && Hash === arg
1010
super
1111
end
1212
end

lib/generators/decent_exposure/scaffold_templates_generator.rb

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
require 'rails/generators'
1+
require "rails/generators"
22

33
module DecentExposure
44
module Generators
55
class ScaffoldTemplatesGenerator < Rails::Generators::Base
6-
desc 'Generate DecentExposure scaffold template files'
7-
source_root File.expand_path('../templates', __FILE__)
8-
class_option :template_engine, desc: 'Template engine to be invoked (erb).'
6+
desc "Generate DecentExposure scaffold template files"
7+
source_root File.expand_path("../templates", __FILE__)
8+
class_option :template_engine, desc: "Template engine to be invoked (erb)."
99

10-
VIEWS = %i(_form edit index new show)
11-
AVAILABLE_ENGINES = %w(erb haml)
10+
VIEWS = %i[_form edit index new show]
11+
AVAILABLE_ENGINES = %w[erb haml]
1212

1313
def generate
1414
validate_template_engine
@@ -20,7 +20,7 @@ def generate
2020
private
2121

2222
def generate_controller
23-
copy_template('rails/scaffold_controller', 'controller.rb')
23+
copy_template("rails/scaffold_controller", "controller.rb")
2424
end
2525

2626
def generate_view(view)

0 commit comments

Comments
 (0)