raka 0.6.0 → 0.7.2

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: c9181e13ec5517b0c40faba8c2e121a9b44c9da29de439bd5303d8fa5ee50870
4
- data.tar.gz: a4c9f8d7e03f067f8266cf77cef52b2d153111c3b24c13a37f9927fe5b543fe5
3
+ metadata.gz: b2a81d9e837185c89f4c0b306675a40e4196e409d6cbafb1cf094d29493bac18
4
+ data.tar.gz: a2fc038c599be3f1d4ba8e4cc39dbd29d485e24723321a54ce937a243175b36d
5
5
  SHA512:
6
- metadata.gz: 03cfe492010d2621bd84aa0c03f452be71de1d26d1d1e354a608893dca47d512ad666a42fb1c0e1d7b89522ad60acbcdd77a9466da388917a6992c9c9afbc8cd
7
- data.tar.gz: f5f1d930083bf7342cac0285ba625219f6eb24fea7e1d61241e81bceda711a49496fa58b899de89759573143671adc74f142c730cfe7343b3663855ca91fcc1a
6
+ metadata.gz: 520eb293b32a8ce0447fe1219c1a8c99672a50222ba903a7080b01a15efdc98a662b19c122332e8f9dca63bc3ba5a14e4cdd3e0a30f502bb4d6a52b96c98b93d
7
+ data.tar.gz: a8756e782078a30fc3a3751def61862273833e308131fa5a98cd2d60f5dc9a696beaa3caf8f4d6793f5944b9c8a089694d1992717fff42c27f01fcdcaa3a34a6
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.0
1
+ 0.7.2
@@ -37,10 +37,10 @@ class Psql
37
37
 
38
38
  if @create.to_s == 'table'
39
39
  'DROP TABLE IF EXISTS :_schema_:_name_;' \
40
- 'CREATE TABLE :schema:_name_ AS (' + code + ');'
40
+ 'CREATE TABLE :_schema_:_name_ AS (' + code + ');'
41
41
  elsif @create.to_s == 'mview'
42
42
  'DROP MATERIALIZED VIEW IF EXISTS :_schema_:_name_;' \
43
- 'CREATE MATERIALIZED VIEW :schema:_name_ AS (' + code + ');'
43
+ 'CREATE MATERIALIZED VIEW :_schema_:_name_ AS (' + code + ');'
44
44
  else
45
45
  code
46
46
  end
data/lib/raka/token.rb CHANGED
@@ -9,8 +9,7 @@ end
9
9
 
10
10
  # Context to preserve during the token chaining
11
11
  class Context
12
- attr_reader :ext
13
- attr_reader :scopes
12
+ attr_reader :ext, :scopes
14
13
 
15
14
  def initialize(ext, scopes = [])
16
15
  @ext = ext
@@ -36,6 +35,7 @@ class Token
36
35
  @inline_scope = inline_scope
37
36
  @options = {}
38
37
  @options[:input_exts] = input_exts
38
+ @compiler_options = @compiler.instance_variable_get(:@options)
39
39
  end
40
40
 
41
41
  def _options_
@@ -53,7 +53,7 @@ class Token
53
53
  # xxx? is for minimal match
54
54
  out_pattern = %r{^((?<scope>\S+)/)?}.source
55
55
  out_pattern += %r{(?<target_scope>#{@inline_scope})/}.source unless @inline_scope.nil?
56
- out_pattern += /(?<stem>(\S+))(?<ext>\.[^\.]+)$/.source
56
+ out_pattern += /(?<stem>(\S+))(?<ext>\.[^.]+)$/.source
57
57
  info = Regexp.new(out_pattern).match(output)
58
58
  res = Hash[info.names.zip(info.captures)]
59
59
  unless info[:scope].nil?
@@ -153,23 +153,47 @@ class Token
153
153
  end
154
154
 
155
155
  # These two methods indicate that this is a pattern token
156
- def [](pattern)
156
+ def [](pattern, options = {})
157
157
  symbol = @chain.pop.to_s
158
158
  # if the pattern contains child pattern like percent_(\d+), we change the capture to
159
159
  # named capture so that it can be captured later. The name is symbol with the index, like func0
160
160
  pattern = pattern.to_s.gsub(/\(\S+?\)/).with_index { |m, i| "(?<#{symbol}#{i}>#{m})" }
161
161
 
162
+ # merge global pattern defaults with provided options
163
+ options = @compiler_options&.pattern_options&.merge(options)
164
+
165
+ # build the pattern based on match mode
166
+ refined_pattern = case options[:match_mode]
167
+ when 'exact'
168
+ pattern.to_s
169
+ when 'prefix'
170
+ "#{pattern}\\w*"
171
+ else
172
+ raise "Invalid match_mode: #{match_mode}. Use 'exact' or 'prefix'"
173
+ end
174
+
162
175
  # if the symbol is _, \S+ will be put in chain, it indicates not to capture,
163
176
  # so just replace it with the refined pattern
164
177
  if symbol == Pattern::ANY # match-everything and not bound
165
- @chain.push "#{pattern}\\w*"
178
+ @chain.push refined_pattern
166
179
  else
167
- @chain.push "(?<#{symbol}>(#{pattern}\\w*))"
180
+ @chain.push "(?<#{symbol}>(#{refined_pattern}))"
168
181
  end
169
182
  self
170
183
  end
171
184
 
172
- def []=(pattern, value)
173
- @compiler.compile(self[pattern], value)
185
+ def []=(pattern, *args)
186
+ case args.length
187
+ when 1
188
+ # Standard: txt._[:pattern] = value
189
+ value = args[0]
190
+ @compiler.compile(self[pattern], value)
191
+ when 2
192
+ # With options: txt._[:pattern, {match_mode: 'exact'}] = value
193
+ options, value = args
194
+ @compiler.compile(self[pattern, options], value)
195
+ else
196
+ raise ArgumentError, "wrong number of arguments (given #{args.length + 1}, expected 2 or 3)"
197
+ end
174
198
  end
175
199
  end
data/lib/raka.rb CHANGED
@@ -46,8 +46,10 @@ class Raka
46
46
  type_aliases: {},
47
47
  scopes: [],
48
48
  lang: ['lang/shell'],
49
- user_lang: []
49
+ user_lang: [],
50
+ pattern_options: { match_mode: 'prefix' }
50
51
  }
52
+ options[:pattern_options] = defaults[:pattern_options].merge(options[:pattern_options] || {})
51
53
  @options = options = OpenStruct.new(defaults.merge(options))
52
54
 
53
55
  create_logger options.log_level || (ENV['LOG_LEVEL'] || Logger::INFO).to_i
@@ -58,7 +60,7 @@ class Raka
58
60
  end
59
61
  # specify root of scopes in options, scopes will append to each root
60
62
  @scopes = options.scopes.empty? ? [] : [options.scopes]
61
- @options.lang.each { |path| load File::join(File::dirname(__FILE__), "raka/#{path}/impl.rb") }
63
+ @options.lang.each { |path| load File.join(File.dirname(__FILE__), "raka/#{path}/impl.rb") }
62
64
  @options.user_lang.each { |path| load path.to_s + '.rb' }
63
65
 
64
66
  # These are where the dsl starts
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: raka
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - yarray