bade 0.3.2 → 0.3.5

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: 5a90545fdee8d531bb87e12dd7943c0486daf3eac68f1d0c69ba216c7595f452
4
- data.tar.gz: cdbf2cbc427cb9dd590768d493f99c91f22ac51a0a3caa172abb0b6c96b81b57
3
+ metadata.gz: 6f328f0e5c63c627084b539186d88cf638e1f74a04b0176e21b50fa9e44744cd
4
+ data.tar.gz: fea38cc7b66f3a5104b3f981d2194d60131cc111240767b67ac5bcd225add4e5
5
5
  SHA512:
6
- metadata.gz: 88708cad2d3145bfe33fb2ca65acbd795b3f8b3074da64f53e8d053d09925a3f750627893c303c2000fe4e9e8328abf4b9fe60a8e1c925a4ccb8966f37887fff
7
- data.tar.gz: 8b21e240977c4f4c0c0387c244dcfb215141e453e04fde9f47762cb59ec22f43ee8056a17c39f41037d52b2a3d2bde8f66ad2b7623d8f8819f9444eebb075741
6
+ metadata.gz: c79cbb86a9d154c1df45d0aabca8131e62051c2cac257f533e13e1866291fa78d655d4fd6a894d36e042ac4f690f2e74082c3868022c8e4607156be0abdcfab8
7
+ data.tar.gz: 4c411d64a549987eba7fc04b72f110025fd5ccccf6b05bcbed79ba8526f177faaf2c3661184f02b9b91f8bf5a1d04044758067050cdc348ddd027e95f6e625dd
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']
@@ -381,7 +381,7 @@ module Bade
381
381
  when :code
382
382
  value = node.value.strip
383
383
 
384
- %w[end else }].include?(value) || value.match(/^(when|elsif) /)
384
+ %w[end else }].include?(value) || value.match(/^(when|elsif) /) || value.match(/^\./)
385
385
  when :newline
386
386
  true
387
387
  else
@@ -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/runtime.rb CHANGED
@@ -31,7 +31,7 @@ module Bade
31
31
  @print_locations_warning = print_locations_warning
32
32
  end
33
33
 
34
- def message
34
+ def to_s
35
35
  if @template_backtrace.empty?
36
36
  super
37
37
  else
@@ -85,7 +85,7 @@ module Bade
85
85
  # get only locations inside template
86
86
  new_locations = new_locations[0...index] || []
87
87
 
88
- # filter out not interested locations
88
+ # filter out not interested locations
89
89
  new_locations
90
90
  .reject { |loc| loc.path.start_with?(__dir__) }
91
91
  .reject { |loc| loc.template? && loc.label.include?('lambda_instance') }
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.2'.freeze
4
+ VERSION = '0.3.5'.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.2
4
+ version: 0.3.5
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-05-04 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.5
138
138
  signing_key:
139
139
  specification_version: 4
140
140
  summary: Minimalistic template engine for Ruby.