bade 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 631a47a8189e2172e6133dbcdd577b741446c493bd4d4fb9e3e7b3e902928891
4
- data.tar.gz: 975e1ba152e0792d950577e6dbdcf12562a23300692479dc5a9b237c6c06b1e7
3
+ metadata.gz: 7a51d23b5cdbf2a6555552edd39164fc3b39b99f381cf454872cce827d5cae77
4
+ data.tar.gz: b7a98aaee99316d20f22d45c36430d8ba1c785e9d316615343bbb539e86c8891
5
5
  SHA512:
6
- metadata.gz: 1ebff9a8a22bd7a6dc902e76af2aeec794f95942469f2cc572d97b6cf19d8ceb23c0b1a778391b612a3b35583b5e7c9cc0dfdd9b3f6ea7423e5af943625659b1
7
- data.tar.gz: ea97fdd39475caf4270535dd7b4af2dbcbcf929bd22cdb080b5b2a5618ad81f8e2796a467b3428a404dd789cb6443b34b9b889ddd32ed37288e1055b5c8446f9
6
+ metadata.gz: 83a93a132f7b957b6d5cd18b4a83c955fa4cd5c68a68d057fa1fec9643ca1c4b2a965c56f7692a0ee3760fafb4732817697d44ca76d35fefdf421204565fe8c0
7
+ data.tar.gz: d59fc4be093b3a2f40f0999e3718f2a0f7bed68956860163cc6920b1cb2afb46459ef155af63fdb8496b9b772055e1d8ffdb956dba173347ab531bb7ca002705
data/Bade.gemspec CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.metadata = { 'rubygems_mfa_required' => 'true' }
18
18
  spec.required_ruby_version = '>= 2.5'
19
19
 
20
- spec.files = Dir['bin/**/*'] + Dir['lib/**/*'] + %w[Bade.gemspec Gemfile README.md]
20
+ spec.files = Dir['lib/**/*'] + %w[Bade.gemspec Gemfile README.md]
21
21
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
22
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
23
23
  spec.require_paths = ['lib']
@@ -1,6 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'utils/where'
3
+ unless Object.respond_to?(:const_source_location)
4
+ class Object
5
+ def Object.const_source_location(name)
6
+ require_relative 'utils/where'
7
+
8
+ konst = const_get(name)
9
+ is_meta = konst.is_a?(Module) || konst.is_a?(Class)
10
+ if is_meta
11
+ Bade.where_is(konst)
12
+ else
13
+ nil
14
+ end
15
+ end
16
+ end
17
+ end
4
18
 
5
19
  module Bade
6
20
  module Runtime
@@ -9,7 +23,7 @@ module Bade
9
23
  # @return [Array<Symbol>]
10
24
  attr_accessor :caught_variables
11
25
 
12
- # @return [Array<[Object, :Symbol]>]
26
+ # @return [Array<[Object, Symbol]>]
13
27
  attr_accessor :caught_constants
14
28
 
15
29
  # @return [Array<String>, nil]
@@ -66,20 +80,24 @@ module Bade
66
80
 
67
81
  # Filteres caught constants by location prefixes and returns ones that should be removed.
68
82
  #
69
- # @return [Array<[Object, :Symbol]>]
83
+ # @return [Array<[Object, Symbol]>]
70
84
  def _filtered_constants
71
85
  @caught_constants.select do |(obj, name)|
72
86
  next unless obj.const_defined?(name)
73
- next true if constants_location_prefixes.nil?
74
87
 
75
- konst = obj.const_get(name)
76
88
  begin
77
- location = Bade.where_is(konst)
89
+ location = obj.const_source_location(name)
78
90
  rescue ::ArgumentError
79
91
  next
80
92
  end
81
93
 
94
+ next true if location.nil?
95
+
82
96
  path = location.first
97
+ next false if $LOADED_FEATURES.include?(path)
98
+
99
+ next true if constants_location_prefixes.nil?
100
+
83
101
  constants_location_prefixes&.any? { |prefix| path.start_with?(prefix) }
84
102
  end
85
103
  end
@@ -85,14 +85,10 @@ module Bade
85
85
 
86
86
  # @param [String] filename
87
87
  def __load(filename)
88
- # FakeFS does not fake `load` method
89
- if Object.const_defined?(:FakeFS) && Object.const_get(:FakeFS).activated?
90
- # rubocop:disable Security/Eval
91
- eval(File.read(filename), __get_binding, filename)
92
- # rubocop:enable Security/Eval
93
- else
94
- load(filename)
95
- end
88
+ # Universal way to load Ruby file (production or during tests)
89
+ # rubocop:disable Security/Eval
90
+ eval(File.read(filename), __get_binding, filename)
91
+ # rubocop:enable Security/Eval
96
92
  end
97
93
 
98
94
  # @param [String] filename
@@ -5,14 +5,22 @@
5
5
  module Bade
6
6
  module Where
7
7
  class << self
8
+ # @param [Proc] proc
9
+ # @return [[String, Integer], String]
8
10
  def is_proc(proc)
9
11
  source_location(proc)
10
12
  end
11
13
 
14
+ # @param [Class] klass
15
+ # @param [Symbol, String] method_name
16
+ # @return [[String, Integer], String]
12
17
  def is_method(klass, method_name)
13
18
  source_location(klass.method(method_name))
14
19
  end
15
20
 
21
+ # @param [Object] klass
22
+ # @param [Symbol, String] method_name
23
+ # @return [[String, Integer], String]
16
24
  def is_instance_method(klass, method_name)
17
25
  source_location(klass.instance_method(method_name))
18
26
  end
@@ -25,6 +33,8 @@ module Bade
25
33
  are_via_extractor(:method, klass, method_name)
26
34
  end
27
35
 
36
+ # @param [Class] klass
37
+ # @return [[String, Integer], String]
28
38
  def is_class(klass)
29
39
  defined_methods(klass)
30
40
  .group_by { |sl| sl[0] }
@@ -61,6 +71,8 @@ module Bade
61
71
 
62
72
  private
63
73
 
74
+ # @param [Method] method
75
+ # @return [[String, Integer], String]
64
76
  def source_location(method)
65
77
  method.source_location || (
66
78
  method.to_s =~ /: (.*)>/
@@ -77,6 +89,7 @@ module Bade
77
89
  .compact
78
90
  end
79
91
 
92
+ # @return [Array<Method>]
80
93
  def defined_methods(klass)
81
94
  methods = klass.methods(false).map { |m| klass.method(m) } +
82
95
  klass.instance_methods(false).map { |m| klass.instance_method(m) }
@@ -87,6 +100,9 @@ module Bade
87
100
  end
88
101
  end
89
102
 
103
+ # @param [Object, Class] klass
104
+ # @param [String, Symbol] method
105
+ # @return [[String, Integer], String]
90
106
  def self.where_is(klass, method = nil)
91
107
  if method
92
108
  begin
data/lib/bade/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bade
4
- VERSION = '0.3.3'.freeze
4
+ VERSION = '0.3.4'.freeze
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bade
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Kříž
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-22 00:00:00.000000000 Z
11
+ date: 2022-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: psych
@@ -134,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
134
  - !ruby/object:Gem::Version
135
135
  version: '0'
136
136
  requirements: []
137
- rubygems_version: 3.3.9
137
+ rubygems_version: 3.3.10
138
138
  signing_key:
139
139
  specification_version: 4
140
140
  summary: Minimalistic template engine for Ruby.