diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index eab6609..e43a0bb 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2025-11-28 15:41:06 UTC using RuboCop version 1.81.7. +# on 2025-12-01 11:50:08 UTC using RuboCop version 1.81.7. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -9,34 +9,34 @@ # Offense count: 4 # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. Metrics/AbcSize: - Max: 49 + Max: 53 # Offense count: 2 # Configuration parameters: CountComments, CountAsOne. Metrics/ClassLength: - Max: 200 + Max: 206 # Offense count: 3 # Configuration parameters: AllowedMethods, AllowedPatterns. Metrics/CyclomaticComplexity: - Max: 17 + Max: 18 # Offense count: 4 # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. Metrics/MethodLength: - Max: 31 + Max: 35 # Offense count: 2 # Configuration parameters: AllowedMethods, AllowedPatterns. Metrics/PerceivedComplexity: - Max: 19 + Max: 21 # Offense count: 1 Naming/AccessorMethodName: Exclude: - 'lib/glug/layer.rb' -# Offense count: 1 +# Offense count: 5 # Configuration parameters: CountAsOne. RSpec/ExampleLength: Max: 53 diff --git a/README.md b/README.md index 2b6a3f6..60e3b8e 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ You create a layer like this: The layer call begins with the layer id (`:water`) and then any additional layer-wide properties (source, source_layer, metadata, interactive). If no source is specified, the default will be used. If no source_layer is specified, the layer id will be used - so in this case, Glug would assume a source_layer of 'water'. -Zoom levels are always specified as Ruby ranges (`5..13`) rather than separate minzoom/maxzoom properties. +Zoom levels are always specified as Ruby ranges (`5..13`) rather than separate minzoom/maxzoom properties. "Beginless" and "Endless" ranges (e.g. `..5` or `13..`) are supported. ### Style definitions diff --git a/lib/glug/layer.rb b/lib/glug/layer.rb index 144719a..1812962 100644 --- a/lib/glug/layer.rb +++ b/lib/glug/layer.rb @@ -253,8 +253,12 @@ def to_hash # Convert zoom level if (v = hash['zoom']) - hash['minzoom'] = v.is_a?(Range) ? v.first : v - hash['maxzoom'] = v.is_a?(Range) ? v.last : v + if v.is_a?(Range) + hash['minzoom'] = v.first unless v.begin.nil? + hash['maxzoom'] = v.last unless v.end.nil? + else + hash['minzoom'] = hash['maxzoom'] = v + end hash.delete('zoom') end diff --git a/spec/lib/glug/layer_spec.rb b/spec/lib/glug/layer_spec.rb index 5759aaf..7cb11b6 100644 --- a/spec/lib/glug/layer_spec.rb +++ b/spec/lib/glug/layer_spec.rb @@ -25,5 +25,33 @@ expect(h['minzoom']).to be(1) expect(h['maxzoom']).to be(5) end + + context 'with endless ranges' do + it 'does not set a max zoom' do + stylesheet = Glug::Stylesheet.new do + source :osm_data, type: 'vector', url: 'http://example.com/osm.tilejson', default: true + end + l = described_class.new(stylesheet, { zoom: 1.. }) + l.line_width 1 + + h = l.to_hash + expect(h).to have_key('minzoom') + expect(h['minzoom']).to be(1) + expect(h).not_to have_key('maxzoom') + end + + it 'does not set a min zoom' do + stylesheet = Glug::Stylesheet.new do + source :osm_data, type: 'vector', url: 'http://example.com/osm.tilejson', default: true + end + l = described_class.new(stylesheet, { zoom: ..5 }) + l.line_width 1 + + h = l.to_hash + expect(h).not_to have_key('minzoom') + expect(h).to have_key('maxzoom') + expect(h['maxzoom']).to be(5) + end + end end end