referral 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +3 -2
- data/lib/referral/filters_tokens.rb +9 -4
- data/lib/referral/matches_token_names.rb +6 -6
- data/lib/referral/parses_options.rb +1 -0
- data/lib/referral/translates_node_to_token.rb +1 -11
- data/lib/referral/value/options.rb +1 -0
- data/lib/referral/value/token.rb +12 -2
- data/lib/referral/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b444d6e3e344bd102380397e714039e2b72834f1f2f6c1023837fa097d215ee
|
4
|
+
data.tar.gz: 46c19b9d8deccaeb7fd1e6489b765fddce2e039bd09790d7a952de429c87b36d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75394674def26ffe7236d85d5c8bb1bef4af3b10d752cfb4e7a1c544f75730bdd16b1e53054351e2bcf36935ce4dca8339797f32c186965c5b6b6b51773eecce
|
7
|
+
data.tar.gz: 4d9d68316c18f98ca8f42694bc661e2e7aa1a3549eae2757707c5745240bf23884a0800a2922765482a02e0a531da5ad354d0fcc56419d18a6bffd749b91cc2e
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -216,8 +216,9 @@ Usage: referral [options] files
|
|
216
216
|
-n, --name [NAME] Partial or complete name(s) to filter
|
217
217
|
--exact-name [NAME] Exact name(s) to filter
|
218
218
|
--full-name [NAME] Exact, fully-qualified name(s) to filter
|
219
|
+
--scope [SCOPE] Scope(s) in which to filter (e.g. Hastack#hide)
|
219
220
|
-p, --pattern [PATTERN] Regex pattern to filter
|
220
|
-
-t, --type [TYPES]
|
221
|
+
-t, --type [TYPES] Include only certain types. See Referral::TOKEN_TYPES.
|
221
222
|
--include-unnamed Include reference without identifiers (default: false)
|
222
223
|
-s, --sort {file,scope} (default: file). See Referral::SORT_FUNCTIONS
|
223
224
|
--print-headers Print header names (default: false)
|
@@ -227,7 +228,7 @@ Usage: referral [options] files
|
|
227
228
|
|
228
229
|
A few things to note:
|
229
230
|
|
230
|
-
* Each of `--name`, `--exact-name`, `--full-name`, `--type`, and `--columns`
|
231
|
+
* Each of `--name`, `--exact-name`, `--full-name`, `--scope`, `--type`, and `--columns`
|
231
232
|
accept comma-separated arrays (e.g. `--name foo,bar,baz`)
|
232
233
|
|
233
234
|
* You can browse available sort functions [in
|
@@ -9,12 +9,17 @@ module Referral
|
|
9
9
|
},
|
10
10
|
exact_name: ->(token, exact_names) {
|
11
11
|
exact_names.any? { |query|
|
12
|
-
MatchesTokenNames.subset(token, query)
|
12
|
+
MatchesTokenNames.subset(token.full_name_tokens, query)
|
13
13
|
}
|
14
14
|
},
|
15
|
-
full_name: ->(token,
|
16
|
-
|
17
|
-
MatchesTokenNames.entirely(token, query)
|
15
|
+
full_name: ->(token, full_names) {
|
16
|
+
full_names.any? { |query|
|
17
|
+
MatchesTokenNames.entirely(token.full_name_tokens, query)
|
18
|
+
}
|
19
|
+
},
|
20
|
+
scope: ->(token, scope_names) {
|
21
|
+
scope_names.any? { |query|
|
22
|
+
MatchesTokenNames.subset(token.scope_tokens, query)
|
18
23
|
}
|
19
24
|
},
|
20
25
|
pattern: ->(token, regex) {
|
@@ -1,18 +1,18 @@
|
|
1
1
|
module Referral
|
2
2
|
class MatchesTokenNames
|
3
|
-
def self.subset(
|
4
|
-
token_tokens =
|
3
|
+
def self.subset(tokens, query)
|
4
|
+
token_tokens = names_from_tokens(tokens)
|
5
5
|
query_tokens = names_from_query(query)
|
6
6
|
|
7
7
|
token_tokens & query_tokens == query_tokens
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.entirely(
|
11
|
-
|
10
|
+
def self.entirely(tokens, query)
|
11
|
+
names_from_tokens(tokens) == names_from_query(query)
|
12
12
|
end
|
13
13
|
|
14
|
-
def self.
|
15
|
-
|
14
|
+
def self.names_from_tokens(tokens)
|
15
|
+
tokens.reject { |t| t.name.nil? }.map { |t| t.name.to_s }
|
16
16
|
end
|
17
17
|
|
18
18
|
def self.names_from_query(query)
|
@@ -22,6 +22,7 @@ module Referral
|
|
22
22
|
op.on("-n", "--name [NAME]", Array, "Partial or complete name(s) to filter")
|
23
23
|
op.on("--exact-name [NAME]", Array, "Exact name(s) to filter")
|
24
24
|
op.on("--full-name [NAME]", Array, "Exact, fully-qualified name(s) to filter")
|
25
|
+
op.on("--scope [SCOPE]", Array, "Scope(s) in which to filter (e.g. Hastack#hide)")
|
25
26
|
op.on("-p", "--pattern [PATTERN]", Regexp, "Regex pattern to filter")
|
26
27
|
op.on("-t", "--type [TYPES]", Array, "Include only certain types. See Referral::TOKEN_TYPES.")
|
27
28
|
op.on("--include-unnamed", TrueClass, "Include reference without identifiers (default: false)")
|
@@ -9,21 +9,11 @@ module Referral
|
|
9
9
|
Value::Token.new(
|
10
10
|
name: type.name_finder.call(node),
|
11
11
|
node_type: type,
|
12
|
-
parent:
|
12
|
+
parent: parent,
|
13
13
|
file: file,
|
14
14
|
line: node.first_lineno,
|
15
15
|
column: node.first_column
|
16
16
|
)
|
17
17
|
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def parent_unless_bad_parent(parent_token, type)
|
22
|
-
return parent_token if parent_token&.node_type&.good_parent
|
23
|
-
|
24
|
-
# puts "should a #{parent_token.node_type.name} parent a #{type.name}?"
|
25
|
-
# return if parent_token.node_type.name == :local_var_assign
|
26
|
-
# parent_token
|
27
|
-
end
|
28
18
|
end
|
29
19
|
end
|
data/lib/referral/value/token.rb
CHANGED
@@ -15,8 +15,18 @@ module Referral
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def scope
|
18
|
-
|
19
|
-
|
18
|
+
join_names(scope_tokens)
|
19
|
+
end
|
20
|
+
|
21
|
+
def scope_tokens
|
22
|
+
return [] if parent.nil?
|
23
|
+
|
24
|
+
ancestors.take_while { |t| t.node_type.good_parent }.flat_map(&:literal_name_tokens)
|
25
|
+
end
|
26
|
+
|
27
|
+
def ancestors
|
28
|
+
return [] if parent.nil?
|
29
|
+
[*parent.ancestors, parent]
|
20
30
|
end
|
21
31
|
|
22
32
|
def full_name
|
data/lib/referral/version.rb
CHANGED