Skip to content

Commit 12f666c

Browse files
committed
rubocop -a
1 parent 37730c3 commit 12f666c

File tree

77 files changed

+648
-724
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+648
-724
lines changed

.rubocop.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,30 @@ Rails:
1717
Metrics/LineLength:
1818
Max: 150
1919

20+
Metrics/MethodLength:
21+
Max: 100
22+
23+
Metrics/BlockLength:
24+
Max: 50
25+
26+
Metrics/ClassLength:
27+
Enabled: false
28+
2029
Style/GuardClause:
2130
Enabled: false
2231

2332
Style/Documentation:
2433
Enabled: false
2534

35+
Style/ClassAndModuleChildren:
36+
Enabled: false
37+
38+
Naming/AccessorMethodName:
39+
Enabled: false
40+
41+
Naming/MemoizedInstanceVariableName:
42+
Enabled: false
43+
2644
# Prefer assert_not over assert !
2745
Rails/AssertNot:
2846
Include:

app/models/form_core/form.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ class Form < ApplicationRecord
66

77
self.table_name = "forms"
88

9-
has_many :fields
9+
has_many :fields, dependent: :destroy
1010
end
1111
end

db/migrate/20170430190404_create_forms.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class CreateForms < ActiveRecord::Migration[5.1]
44
def change
55
create_table :forms do |t|
6-
t.string :name, null: false, index: {unique: true}
6+
t.string :name, null: false, index: { unique: true }
77
t.string :type, null: false, index: true
88

99
t.timestamps

lib/form_core.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ def virtual_model_class
1818
end
1919

2020
def virtual_model_class=(klass)
21-
unless klass && klass < VirtualModel
22-
raise ArgumentError, "#{klass} should be sub-class of #{VirtualModel}."
23-
end
21+
raise ArgumentError, "#{klass} should be sub-class of #{VirtualModel}." unless klass && klass < VirtualModel
2422

2523
@reserved_names = nil
2624
@virtual_model_class = klass
@@ -38,9 +36,7 @@ def virtual_model_coder_class
3836
end
3937

4038
def virtual_model_coder_class=(klass)
41-
unless klass && klass < Coder
42-
raise ArgumentError, "#{klass} should be sub-class of #{Coder}."
43-
end
39+
raise ArgumentError, "#{klass} should be sub-class of #{Coder}." unless klass && klass < Coder
4440

4541
@virtual_model_coder_class = klass
4642
end

lib/form_core/coder.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,20 @@ def load(_src)
2424

2525
private
2626

27-
def new_or_raise_decoding_error
28-
if strict?
29-
raise DecodingDataCorrupted
30-
else
31-
object_class.new
27+
def new_or_raise_decoding_error
28+
if strict?
29+
raise DecodingDataCorrupted
30+
else
31+
object_class.new
32+
end
3233
end
33-
end
3434

35-
def valid_attribute_names
36-
object_class.attribute_names + object_class._embeds_reflections.keys
37-
end
35+
def valid_attribute_names
36+
object_class.attribute_names + object_class._embeds_reflections.keys
37+
end
3838

39-
def valid_attributes(hash)
40-
hash.slice(*valid_attribute_names)
41-
end
39+
def valid_attributes(hash)
40+
hash.slice(*valid_attribute_names)
41+
end
4242
end
4343
end

lib/form_core/coders/hash_coder.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ def dump(obj)
99
end
1010

1111
def load(hash)
12-
if hash.nil? || !hash.respond_to?(:to_h)
13-
return new_or_raise_decoding_error
14-
end
12+
return new_or_raise_decoding_error if hash.nil? || !hash.respond_to?(:to_h)
1513

1614
object_class.new valid_attributes(hash)
1715
end

lib/form_core/coders/yaml_coder.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,15 @@ def dump(obj)
2323
def load(yaml)
2424
return object_class.new if yaml.blank?
2525

26-
unless yaml.is_a?(String) && /^---/.match?(yaml)
27-
return new_or_raise_decoding_error
28-
end
26+
return new_or_raise_decoding_error unless yaml.is_a?(String) && /^---/.match?(yaml)
2927

3028
decoded =
3129
if safe_mode?
3230
YAML.safe_load(yaml, YAMLCoder.whitelist_classes)
3331
else
34-
YAML.load(yaml)
32+
YAML.safe_load(yaml)
3533
end
36-
unless decoded.is_a? Hash
37-
return new_or_raise_decoding_error
38-
end
34+
return new_or_raise_decoding_error unless decoded.is_a? Hash
3935

4036
object_class.new valid_attributes(decoded)
4137
end

lib/form_core/concerns/models/field.rb

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ module Field
88
NAME_REGEX = /\A[a-z][a-z_0-9]*\z/.freeze
99

1010
included do
11-
enum accessibility: {read_and_write: 0, readonly: 1, hidden: 2},
11+
enum accessibility: { read_and_write: 0, readonly: 1, hidden: 2 },
1212
_prefix: :access
1313

1414
serialize :validations
1515
serialize :options
1616

1717
validates :name,
1818
presence: true,
19-
uniqueness: {scope: :form},
20-
exclusion: {in: FormCore.reserved_names},
21-
format: {with: NAME_REGEX}
19+
uniqueness: { scope: :form },
20+
exclusion: { in: FormCore.reserved_names },
21+
format: { with: NAME_REGEX }
2222
validates :accessibility,
23-
inclusion: {in: accessibilities.keys.map(&:to_sym)}
23+
inclusion: { in: accessibilities.keys.map(&:to_sym) }
2424

2525
after_initialize do
2626
self.validations ||= {}
@@ -54,9 +54,7 @@ def interpret_to(model, overrides: {})
5454
default_value = overrides.fetch(:default_value, self.default_value)
5555
model.attribute name, stored_type, default: default_value
5656

57-
if accessibility == :readonly
58-
model.attr_readonly name
59-
end
57+
model.attr_readonly name if accessibility == :readonly
6058

6159
interpret_validations_to model, accessibility, overrides
6260
interpret_extra_to model, accessibility, overrides
@@ -66,22 +64,18 @@ def interpret_to(model, overrides: {})
6664

6765
protected
6866

69-
def interpret_validations_to(model, accessibility, overrides = {})
70-
validations = overrides.fetch(:validations, (self.validations || {}))
71-
validation_options = overrides.fetch(:validation_options) { self.options.fetch(:validation, {}) }
67+
def interpret_validations_to(model, accessibility, overrides = {})
68+
validations = overrides.fetch(:validations, (self.validations || {}))
69+
validation_options = overrides.fetch(:validation_options) { self.options.fetch(:validation, {}) }
7270

73-
if accessibility == :read_and_write && validations.present?
74-
model.validates name, **validations, **validation_options
71+
model.validates name, **validations, **validation_options if accessibility == :read_and_write && validations.present?
7572
end
76-
end
7773

78-
def interpret_extra_to(_model, _accessibility, _overrides = {}); end
74+
def interpret_extra_to(_model, _accessibility, _overrides = {}); end
7975

80-
def check_model_validity!(model)
81-
unless model.is_a?(Class) && model < ::FormCore::VirtualModel
82-
raise ArgumentError, "#{model} must be a #{::FormCore::VirtualModel}'s subclass"
76+
def check_model_validity!(model)
77+
raise ArgumentError, "#{model} must be a #{::FormCore::VirtualModel}'s subclass" unless model.is_a?(Class) && model < ::FormCore::VirtualModel
8378
end
84-
end
8579
end
8680
end
8781
end

lib/form_core/concerns/models/form.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ module Form
1111
validates :name,
1212
presence: true,
1313
uniqueness: true,
14-
exclusion: {in: FormCore.reserved_names},
15-
format: {with: NAME_REGEX}
14+
exclusion: { in: FormCore.reserved_names },
15+
format: { with: NAME_REGEX }
1616
end
1717

1818
def to_virtual_model(model_name: "Form",
@@ -38,11 +38,11 @@ def append_to_virtual_model(model,
3838

3939
private
4040

41-
def check_model_validity!(model)
42-
unless model.is_a?(Class) && model < ::FormCore::VirtualModel
43-
raise ArgumentError, "#{model} must be a #{::FormCore::VirtualModel}'s subclass"
41+
def check_model_validity!(model)
42+
unless model.is_a?(Class) && model < ::FormCore::VirtualModel
43+
raise ArgumentError, "#{model} must be a #{::FormCore::VirtualModel}'s subclass"
44+
end
4445
end
45-
end
4646
end
4747
end
4848
end

lib/form_core/virtual_model.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ def inspect
1111
inspection =
1212
if defined?(@attributes) && @attributes
1313
self.class.attribute_names.collect do |name|
14-
if has_attribute?(name)
15-
"#{name}: #{attribute_for_inspect(name)}"
16-
end
14+
"#{name}: #{attribute_for_inspect(name)}" if has_attribute?(name)
1715
end.compact.join(", ")
1816
else
1917
"not initialized"
@@ -51,9 +49,7 @@ def coder
5149
end
5250

5351
def coder=(klass)
54-
unless klass && klass < Coder
55-
raise ArgumentError, "#{klass} should be sub-class of #{Coder}."
56-
end
52+
raise ArgumentError, "#{klass} should be sub-class of #{Coder}." unless klass && klass < Coder
5753

5854
@_coder = klass.new(self)
5955
end

0 commit comments

Comments
 (0)