faceter 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +2 -0
- data/.gitignore +9 -0
- data/.metrics +9 -0
- data/.rspec +2 -0
- data/.rubocop.yml +2 -0
- data/.travis.yml +18 -0
- data/.yardopts +3 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +9 -0
- data/Guardfile +10 -0
- data/LICENSE +21 -0
- data/README.md +295 -0
- data/Rakefile +37 -0
- data/benchmark/data.json +1 -0
- data/benchmark/faceter.rb +73 -0
- data/benchmark/rom.rb +85 -0
- data/benchmark/run.rb +54 -0
- data/config/metrics/STYLEGUIDE +230 -0
- data/config/metrics/cane.yml +5 -0
- data/config/metrics/churn.yml +6 -0
- data/config/metrics/flay.yml +2 -0
- data/config/metrics/metric_fu.yml +14 -0
- data/config/metrics/reek.yml +1 -0
- data/config/metrics/roodi.yml +24 -0
- data/config/metrics/rubocop.yml +75 -0
- data/config/metrics/saikuro.yml +3 -0
- data/config/metrics/simplecov.yml +6 -0
- data/config/metrics/yardstick.yml +37 -0
- data/faceter.gemspec +29 -0
- data/lib/faceter.rb +54 -0
- data/lib/faceter/coercers.rb +68 -0
- data/lib/faceter/functions.rb +30 -0
- data/lib/faceter/functions/add_prefix.rb +25 -0
- data/lib/faceter/functions/claster.rb +27 -0
- data/lib/faceter/functions/clean.rb +27 -0
- data/lib/faceter/functions/drop_prefix.rb +29 -0
- data/lib/faceter/functions/exclude.rb +27 -0
- data/lib/faceter/functions/group.rb +41 -0
- data/lib/faceter/functions/keep_symbol.rb +27 -0
- data/lib/faceter/functions/split.rb +28 -0
- data/lib/faceter/functions/ungroup.rb +31 -0
- data/lib/faceter/functions/unwrap.rb +32 -0
- data/lib/faceter/functions/wrap.rb +32 -0
- data/lib/faceter/mapper.rb +38 -0
- data/lib/faceter/nodes/add_prefix.rb +21 -0
- data/lib/faceter/nodes/change_prefix.rb +51 -0
- data/lib/faceter/nodes/create.rb +43 -0
- data/lib/faceter/nodes/exclude.rb +25 -0
- data/lib/faceter/nodes/field.rb +25 -0
- data/lib/faceter/nodes/fold.rb +25 -0
- data/lib/faceter/nodes/group.rb +26 -0
- data/lib/faceter/nodes/list.rb +25 -0
- data/lib/faceter/nodes/remove_prefix.rb +21 -0
- data/lib/faceter/nodes/rename.rb +25 -0
- data/lib/faceter/nodes/stringify_keys.rb +26 -0
- data/lib/faceter/nodes/symbolize_keys.rb +26 -0
- data/lib/faceter/nodes/unfold.rb +25 -0
- data/lib/faceter/nodes/ungroup.rb +26 -0
- data/lib/faceter/nodes/unwrap.rb +26 -0
- data/lib/faceter/nodes/wrap.rb +26 -0
- data/lib/faceter/rules/append_nested.rb +28 -0
- data/lib/faceter/rules/merge_branches.rb +41 -0
- data/lib/faceter/rules/merge_excludes.rb +29 -0
- data/lib/faceter/rules/merge_renames.rb +27 -0
- data/lib/faceter/rules/order_fields.rb +27 -0
- data/lib/faceter/rules/prepend_nested.rb +51 -0
- data/lib/faceter/version.rb +11 -0
- data/spec/integration/commands/add_prefix_spec.rb +37 -0
- data/spec/integration/commands/create_spec.rb +33 -0
- data/spec/integration/commands/exclude_spec.rb +55 -0
- data/spec/integration/commands/fold_spec.rb +41 -0
- data/spec/integration/commands/group_spec.rb +64 -0
- data/spec/integration/commands/remove_prefix_spec.rb +63 -0
- data/spec/integration/commands/rename_spec.rb +45 -0
- data/spec/integration/commands/stringify_keys_spec.rb +65 -0
- data/spec/integration/commands/symbolize_keys_spec.rb +49 -0
- data/spec/integration/commands/unfold_spec.rb +41 -0
- data/spec/integration/commands/ungroup_spec.rb +64 -0
- data/spec/integration/commands/unwrap_spec.rb +51 -0
- data/spec/integration/commands/wrap_spec.rb +51 -0
- data/spec/integration/rom_spec.rb +39 -0
- data/spec/spec_helper.rb +25 -0
- data/spec/unit/coercers/create_spec.rb +16 -0
- data/spec/unit/coercers/exclude_spec.rb +31 -0
- data/spec/unit/coercers/field_spec.rb +11 -0
- data/spec/unit/coercers/fold_spec.rb +11 -0
- data/spec/unit/coercers/prefix_spec.rb +38 -0
- data/spec/unit/coercers/rename_spec.rb +11 -0
- data/spec/unit/coercers/unfold_spec.rb +11 -0
- data/spec/unit/coercers/unwrap_spec.rb +35 -0
- data/spec/unit/coercers/wrap_spec.rb +35 -0
- data/spec/unit/functions/add_prefix_spec.rb +12 -0
- data/spec/unit/functions/claster_spec.rb +12 -0
- data/spec/unit/functions/clean_spec.rb +18 -0
- data/spec/unit/functions/drop_prefix_spec.rb +33 -0
- data/spec/unit/functions/exclude_spec.rb +64 -0
- data/spec/unit/functions/group_spec.rb +176 -0
- data/spec/unit/functions/keep_symbol_spec.rb +21 -0
- data/spec/unit/functions/split_spec.rb +64 -0
- data/spec/unit/functions/ungroup_spec.rb +87 -0
- data/spec/unit/functions/unwrap_spec.rb +54 -0
- data/spec/unit/functions/wrap_spec.rb +67 -0
- data/spec/unit/nodes/add_prefix_spec.rb +62 -0
- data/spec/unit/nodes/create_spec.rb +53 -0
- data/spec/unit/nodes/exclude_spec.rb +18 -0
- data/spec/unit/nodes/field_spec.rb +30 -0
- data/spec/unit/nodes/fold_spec.rb +19 -0
- data/spec/unit/nodes/group_spec.rb +163 -0
- data/spec/unit/nodes/list_spec.rb +27 -0
- data/spec/unit/nodes/remove_prefix_spec.rb +62 -0
- data/spec/unit/nodes/rename_spec.rb +16 -0
- data/spec/unit/nodes/stringify_keys_spec.rb +21 -0
- data/spec/unit/nodes/symbolize_keys_spec.rb +21 -0
- data/spec/unit/nodes/unfold_spec.rb +19 -0
- data/spec/unit/nodes/ungroup_spec.rb +92 -0
- data/spec/unit/nodes/unwrap_spec.rb +47 -0
- data/spec/unit/nodes/wrap_spec.rb +33 -0
- data/spec/unit/rules/append_nested_spec.rb +41 -0
- data/spec/unit/rules/merge_branches_spec.rb +58 -0
- data/spec/unit/rules/merge_excludes_spec.rb +31 -0
- data/spec/unit/rules/merge_renames_spec.rb +29 -0
- data/spec/unit/rules/order_fields_spec.rb +31 -0
- data/spec/unit/rules/prepend_nested_spec.rb +41 -0
- metadata +315 -0
@@ -0,0 +1,14 @@
|
|
1
|
+
---
|
2
|
+
folders: # The list of folders to be used by any metric.
|
3
|
+
- lib
|
4
|
+
metrics: # The list of allowed metrics. The other metrics are disabled.
|
5
|
+
- cane
|
6
|
+
- churn
|
7
|
+
- flay
|
8
|
+
- flog
|
9
|
+
- reek
|
10
|
+
- roodi
|
11
|
+
- saikuro
|
12
|
+
format: html
|
13
|
+
output: tmp/metric_fu
|
14
|
+
verbose: false
|
@@ -0,0 +1 @@
|
|
1
|
+
---
|
@@ -0,0 +1,24 @@
|
|
1
|
+
---
|
2
|
+
AssignmentInConditionalCheck:
|
3
|
+
CaseMissingElseCheck:
|
4
|
+
ClassLineCountCheck:
|
5
|
+
line_count: 300
|
6
|
+
ClassNameCheck:
|
7
|
+
pattern: !ruby/regexp /^[A-Z][a-zA-Z0-9]*$/
|
8
|
+
ClassVariableCheck:
|
9
|
+
CyclomaticComplexityBlockCheck:
|
10
|
+
complexity: 4
|
11
|
+
CyclomaticComplexityMethodCheck:
|
12
|
+
complexity: 8
|
13
|
+
EmptyRescueBodyCheck:
|
14
|
+
ForLoopCheck:
|
15
|
+
MethodLineCountCheck:
|
16
|
+
line_count: 20
|
17
|
+
MethodNameCheck:
|
18
|
+
pattern: !ruby/regexp /^[\||\^|\&|\!]$|^[_a-z<>=\[|+-\/\*`]+[_a-z0-9_<>=~@\[\]]*[=!\?]?$/
|
19
|
+
ModuleLineCountCheck:
|
20
|
+
line_count: 300
|
21
|
+
ModuleNameCheck:
|
22
|
+
pattern: !ruby/regexp /^[A-Z][a-zA-Z0-9]*$/
|
23
|
+
ParameterNumberCheck:
|
24
|
+
parameter_count: 5
|
@@ -0,0 +1,75 @@
|
|
1
|
+
---
|
2
|
+
# settings added by the 'hexx-suit' module
|
3
|
+
# output: "tmp/rubocop"
|
4
|
+
# format: "html"
|
5
|
+
|
6
|
+
AllCops:
|
7
|
+
Exclude:
|
8
|
+
- '**/db/schema.rb'
|
9
|
+
|
10
|
+
Lint/HandleExceptions:
|
11
|
+
Exclude:
|
12
|
+
- '**/*_spec.rb'
|
13
|
+
|
14
|
+
Lint/RescueException:
|
15
|
+
Exclude:
|
16
|
+
- '**/*_spec.rb'
|
17
|
+
|
18
|
+
Metrics/AbcSize:
|
19
|
+
Max: 17 # default: 15
|
20
|
+
|
21
|
+
Style/AccessorMethodName:
|
22
|
+
Exclude:
|
23
|
+
- '**/*_spec.rb'
|
24
|
+
|
25
|
+
Style/AsciiComments:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
Style/ClassAndModuleChildren:
|
29
|
+
Enabled: false
|
30
|
+
|
31
|
+
Style/Documentation:
|
32
|
+
Enabled: false
|
33
|
+
|
34
|
+
Style/EmptyLinesAroundBlockBody:
|
35
|
+
Enabled: false
|
36
|
+
|
37
|
+
Style/EmptyLinesAroundClassBody:
|
38
|
+
Enabled: false
|
39
|
+
|
40
|
+
Style/EmptyLinesAroundMethodBody:
|
41
|
+
Enabled: false
|
42
|
+
|
43
|
+
Style/EmptyLinesAroundModuleBody:
|
44
|
+
Enabled: false
|
45
|
+
|
46
|
+
Style/EmptyLineBetweenDefs:
|
47
|
+
Enabled: false
|
48
|
+
|
49
|
+
Style/FileName:
|
50
|
+
Enabled: false
|
51
|
+
|
52
|
+
Style/RaiseArgs:
|
53
|
+
EnforcedStyle: compact
|
54
|
+
|
55
|
+
Style/SingleLineMethods:
|
56
|
+
Exclude:
|
57
|
+
- '**/*_spec.rb'
|
58
|
+
|
59
|
+
Style/SingleSpaceBeforeFirstArg:
|
60
|
+
Enabled: false
|
61
|
+
|
62
|
+
Style/SpecialGlobalVars:
|
63
|
+
Exclude:
|
64
|
+
- '**/Gemfile'
|
65
|
+
- '**/*.gemspec'
|
66
|
+
|
67
|
+
Style/StringLiterals:
|
68
|
+
EnforcedStyle: double_quotes
|
69
|
+
|
70
|
+
Style/StringLiteralsInInterpolation:
|
71
|
+
EnforcedStyle: double_quotes
|
72
|
+
|
73
|
+
Style/TrivialAccessors:
|
74
|
+
Exclude:
|
75
|
+
- '**/*_spec.rb'
|
@@ -0,0 +1,37 @@
|
|
1
|
+
---
|
2
|
+
# Settings added by the 'hexx-suit' gem
|
3
|
+
output: "tmp/yardstick/output.log"
|
4
|
+
path: "lib/**/*.rb"
|
5
|
+
rules:
|
6
|
+
ApiTag::Presence:
|
7
|
+
enabled: true
|
8
|
+
exclude: []
|
9
|
+
ApiTag::Inclusion:
|
10
|
+
enabled: true
|
11
|
+
exclude: []
|
12
|
+
ApiTag::ProtectedMethod:
|
13
|
+
enabled: true
|
14
|
+
exclude: []
|
15
|
+
ApiTag::PrivateMethod:
|
16
|
+
enabled: false
|
17
|
+
exclude: []
|
18
|
+
ExampleTag:
|
19
|
+
enabled: true
|
20
|
+
exclude: []
|
21
|
+
ReturnTag:
|
22
|
+
enabled: true
|
23
|
+
exclude: []
|
24
|
+
Summary::Presence:
|
25
|
+
enabled: true
|
26
|
+
exclude: []
|
27
|
+
Summary::Length:
|
28
|
+
enabled: true
|
29
|
+
exclude: []
|
30
|
+
Summary::Delimiter:
|
31
|
+
enabled: true
|
32
|
+
exclude: []
|
33
|
+
Summary::SingleLine:
|
34
|
+
enabled: true
|
35
|
+
exclude: []
|
36
|
+
threshold: 100
|
37
|
+
verbose: false
|
data/faceter.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
require "faceter/version"
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
|
6
|
+
gem.name = "faceter"
|
7
|
+
gem.version = Faceter::VERSION.dup
|
8
|
+
gem.author = "Andrew Kozin"
|
9
|
+
gem.email = "andrew.kozin@gmail.com"
|
10
|
+
gem.homepage = "https://github.com/nepalez/faceter"
|
11
|
+
gem.summary = "ROM-compatible data mapper"
|
12
|
+
gem.license = "MIT"
|
13
|
+
|
14
|
+
gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
15
|
+
gem.test_files = Dir["spec/**/*.rb"]
|
16
|
+
gem.extra_rdoc_files = Dir["README.md", "LICENSE"]
|
17
|
+
gem.require_paths = ["lib"]
|
18
|
+
|
19
|
+
gem.required_ruby_version = ">= 2.1"
|
20
|
+
|
21
|
+
gem.add_runtime_dependency "abstract_mapper", "~> 0.0", ">= 0.0.2"
|
22
|
+
gem.add_runtime_dependency "selector", "~> 0.0"
|
23
|
+
|
24
|
+
gem.add_development_dependency "hexx-rspec", "~> 0.4"
|
25
|
+
gem.add_development_dependency "rom", "~> 0.8"
|
26
|
+
gem.add_development_dependency "benchmark-ips", "~> 2.2"
|
27
|
+
gem.add_development_dependency "inflecto", "~> 0.0"
|
28
|
+
|
29
|
+
end # Gem::Specification
|
data/lib/faceter.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "abstract_mapper"
|
4
|
+
require "selector"
|
5
|
+
|
6
|
+
# Load specific transformations
|
7
|
+
require_relative "faceter/functions"
|
8
|
+
require_relative "faceter/functions/split"
|
9
|
+
require_relative "faceter/functions/exclude"
|
10
|
+
require_relative "faceter/functions/keep_symbol"
|
11
|
+
require_relative "faceter/functions/add_prefix"
|
12
|
+
require_relative "faceter/functions/drop_prefix"
|
13
|
+
require_relative "faceter/functions/clean"
|
14
|
+
require_relative "faceter/functions/wrap"
|
15
|
+
require_relative "faceter/functions/unwrap"
|
16
|
+
require_relative "faceter/functions/group"
|
17
|
+
require_relative "faceter/functions/ungroup"
|
18
|
+
require_relative "faceter/functions/claster"
|
19
|
+
|
20
|
+
# Load specific AST nodes
|
21
|
+
require_relative "faceter/nodes/list"
|
22
|
+
require_relative "faceter/nodes/field"
|
23
|
+
require_relative "faceter/nodes/change_prefix"
|
24
|
+
require_relative "faceter/nodes/add_prefix"
|
25
|
+
require_relative "faceter/nodes/remove_prefix"
|
26
|
+
require_relative "faceter/nodes/stringify_keys"
|
27
|
+
require_relative "faceter/nodes/symbolize_keys"
|
28
|
+
require_relative "faceter/nodes/create"
|
29
|
+
require_relative "faceter/nodes/exclude"
|
30
|
+
require_relative "faceter/nodes/rename"
|
31
|
+
require_relative "faceter/nodes/fold"
|
32
|
+
require_relative "faceter/nodes/unfold"
|
33
|
+
require_relative "faceter/nodes/wrap"
|
34
|
+
require_relative "faceter/nodes/unwrap"
|
35
|
+
require_relative "faceter/nodes/group"
|
36
|
+
require_relative "faceter/nodes/ungroup"
|
37
|
+
|
38
|
+
# Load specific optimization rules
|
39
|
+
require_relative "faceter/rules/prepend_nested"
|
40
|
+
require_relative "faceter/rules/append_nested"
|
41
|
+
require_relative "faceter/rules/order_fields"
|
42
|
+
require_relative "faceter/rules/merge_branches"
|
43
|
+
require_relative "faceter/rules/merge_renames"
|
44
|
+
require_relative "faceter/rules/merge_excludes"
|
45
|
+
|
46
|
+
# Load the gem-specific base mapper
|
47
|
+
require_relative "faceter/coercers"
|
48
|
+
require_relative "faceter/mapper"
|
49
|
+
|
50
|
+
# ROM-compatible data mapper
|
51
|
+
#
|
52
|
+
module Faceter
|
53
|
+
|
54
|
+
end # module Faceter
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Faceter
|
4
|
+
|
5
|
+
# Collection of functions to coerce command arguments to node attributes
|
6
|
+
#
|
7
|
+
# @api private
|
8
|
+
#
|
9
|
+
module Coercers
|
10
|
+
|
11
|
+
extend Transproc::Registry
|
12
|
+
|
13
|
+
# @private
|
14
|
+
def self.prefix(prefix, **options)
|
15
|
+
filter = options.fetch(:separator) { "_" }
|
16
|
+
nested = options.fetch(:nested) { false }
|
17
|
+
selector = Selector.new(options) if options[:except] || options[:only]
|
18
|
+
{ prefix: prefix, separator: filter, nested: nested, selector: selector }
|
19
|
+
end
|
20
|
+
|
21
|
+
# @private
|
22
|
+
def self.unwrap(*keys, **options)
|
23
|
+
key = options.fetch(:from)
|
24
|
+
opts = (keys.any? ? { only: keys } : {}).merge(options)
|
25
|
+
{ key: key, selector: Selector.new(opts) }
|
26
|
+
end
|
27
|
+
|
28
|
+
# @private
|
29
|
+
def self.wrap(*keys, **options)
|
30
|
+
key = options.fetch(:to)
|
31
|
+
opts = (keys.any? ? { only: keys } : {}).merge(options)
|
32
|
+
{ key: key, selector: Selector.new(opts) }
|
33
|
+
end
|
34
|
+
|
35
|
+
# @private
|
36
|
+
def self.unfold(**options)
|
37
|
+
{ key: options.fetch(:from) }
|
38
|
+
end
|
39
|
+
|
40
|
+
# @private
|
41
|
+
def self.exclude(*keys, **options)
|
42
|
+
opts = keys.any? ? { only: keys } : options
|
43
|
+
{ selector: Selector.new(opts) }
|
44
|
+
end
|
45
|
+
|
46
|
+
# @private
|
47
|
+
def self.create(name, **options)
|
48
|
+
{ name: name, keys: options.fetch(:from) }
|
49
|
+
end
|
50
|
+
|
51
|
+
# @private
|
52
|
+
def self.field(key)
|
53
|
+
{ key: key }
|
54
|
+
end
|
55
|
+
|
56
|
+
# @private
|
57
|
+
def self.fold(**options)
|
58
|
+
{ key: options.fetch(:to) }
|
59
|
+
end
|
60
|
+
|
61
|
+
# @private
|
62
|
+
def self.rename(name, **options)
|
63
|
+
{ keys: { name => options.fetch(:to) } }
|
64
|
+
end
|
65
|
+
|
66
|
+
end # module Coercers
|
67
|
+
|
68
|
+
end # module Faceter
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "transproc/conditional"
|
4
|
+
require "transproc/hash"
|
5
|
+
require "transproc/array"
|
6
|
+
require "transproc/recursion"
|
7
|
+
require "transproc/coercions"
|
8
|
+
|
9
|
+
module Faceter
|
10
|
+
|
11
|
+
# Collection of the gem-specific transformations (pure functions)
|
12
|
+
#
|
13
|
+
# @api private
|
14
|
+
#
|
15
|
+
module Functions
|
16
|
+
|
17
|
+
extend Transproc::Registry
|
18
|
+
|
19
|
+
import Transproc::HashTransformations
|
20
|
+
import Transproc::ArrayTransformations
|
21
|
+
|
22
|
+
import :guard, from: Transproc::Conditional
|
23
|
+
import :identity, from: AbstractMapper::Functions
|
24
|
+
import :is, from: Transproc::Conditional
|
25
|
+
import :recursion, from: Transproc::Recursion
|
26
|
+
import :to_tuples, from: Transproc::Coercions
|
27
|
+
|
28
|
+
end # module Functions
|
29
|
+
|
30
|
+
end # module Faceter
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Faceter
|
4
|
+
|
5
|
+
module Functions
|
6
|
+
|
7
|
+
# Adds the prefix with separator to the string
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# fn = Functions[:add_prefix, "foo", "."]
|
11
|
+
# fn["bar"] # => "foo.bar"
|
12
|
+
#
|
13
|
+
# @param [#to_s] string
|
14
|
+
# @param [#to_s] prefix
|
15
|
+
# @param [#to_s] separator
|
16
|
+
#
|
17
|
+
# @return [String]
|
18
|
+
#
|
19
|
+
def self.add_prefix(string, prefix, separator)
|
20
|
+
"#{prefix}#{separator}#{string}"
|
21
|
+
end
|
22
|
+
|
23
|
+
end # module Functions
|
24
|
+
|
25
|
+
end # module Faceter
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Faceter
|
4
|
+
|
5
|
+
module Functions
|
6
|
+
|
7
|
+
# Break the array to array of consecutive items that matches each other
|
8
|
+
# by given function
|
9
|
+
#
|
10
|
+
# @param [Array] list
|
11
|
+
# @param [#call] fn
|
12
|
+
#
|
13
|
+
# @return [Array]
|
14
|
+
#
|
15
|
+
def self.claster(list, fn)
|
16
|
+
list.each_with_object([[]]) do |e, a|
|
17
|
+
if a.last.eql?([]) || fn[e].equal?(fn[a.last.last])
|
18
|
+
a.last << e
|
19
|
+
else
|
20
|
+
a << [e]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end # module Functions
|
26
|
+
|
27
|
+
end # module Faceter
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Faceter
|
4
|
+
|
5
|
+
module Functions
|
6
|
+
|
7
|
+
# Removes selected keys from hash if they values are empty
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# selector = Selector.new(only: /b/)
|
11
|
+
# function = Functions[:clean, selector]
|
12
|
+
#
|
13
|
+
# function[foo: {}, bar: {}, baz: :BAZ]
|
14
|
+
# # => { foo: {}, baz: :BAZ }
|
15
|
+
#
|
16
|
+
# @param [Hash] hash
|
17
|
+
# @param [Selector::Condition] selector
|
18
|
+
#
|
19
|
+
# @return [Hash]
|
20
|
+
#
|
21
|
+
def self.clean(hash, selector)
|
22
|
+
hash.reject { |key, value| selector[key] && value.empty? }
|
23
|
+
end
|
24
|
+
|
25
|
+
end # module Functions
|
26
|
+
|
27
|
+
end # module Faceter
|