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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bbc3ccfe2fc13d49b4fe81db0b450452485ff2ee6a76d05c4ab04368df20f56b
4
- data.tar.gz: ecdfede161422d2a90f199f718d80ade1eb644c520e5929c71643272295e0728
3
+ metadata.gz: 2b444d6e3e344bd102380397e714039e2b72834f1f2f6c1023837fa097d215ee
4
+ data.tar.gz: 46c19b9d8deccaeb7fd1e6489b765fddce2e039bd09790d7a952de429c87b36d
5
5
  SHA512:
6
- metadata.gz: 10da1ed6a90542750ec6f77ed4258017432f782245fc159dc30ec24c5ac139e12f43ea273260650c810338fdeb4367c6dc1a42aff397d29105935584960d7242
7
- data.tar.gz: 0b8e3682cd38e2acad49887aaddd026c0d85bbe686e39923163b8f87f4f65a132d3ef6086411d2c7959d2eb66475b8d7256f6724c9e09cc50977be22efefecee
6
+ metadata.gz: 75394674def26ffe7236d85d5c8bb1bef4af3b10d752cfb4e7a1c544f75730bdd16b1e53054351e2bcf36935ce4dca8339797f32c186965c5b6b6b51773eecce
7
+ data.tar.gz: 4d9d68316c18f98ca8f42694bc661e2e7aa1a3549eae2757707c5745240bf23884a0800a2922765482a02e0a531da5ad354d0fcc56419d18a6bffd749b91cc2e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- referral (0.0.3)
4
+ referral (0.0.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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] Include only certain types. See Referral::TOKEN_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, exact_names) {
16
- exact_names.any? { |query|
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(token, query)
4
- token_tokens = names_from_token(token)
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(token, query)
11
- names_from_token(token) == names_from_query(query)
10
+ def self.entirely(tokens, query)
11
+ names_from_tokens(tokens) == names_from_query(query)
12
12
  end
13
13
 
14
- def self.names_from_token(token)
15
- token.full_name_tokens.reject { |t| t.name.nil? }.map { |t| t.name.to_s }
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: parent_unless_bad_parent(parent, type),
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
@@ -6,6 +6,7 @@ module Referral
6
6
  :name,
7
7
  :exact_name,
8
8
  :full_name,
9
+ :scope,
9
10
  :pattern,
10
11
  :type,
11
12
  :include_unnamed,
@@ -15,8 +15,18 @@ module Referral
15
15
  end
16
16
 
17
17
  def scope
18
- return "" unless parent
19
- parent.full_name
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
@@ -1,3 +1,3 @@
1
1
  module Referral
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: referral
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Searls