Class: GeoserverMigrations::LayergroupConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/geoserver_migrations/layergroup_config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(layer_name, is_update_style = false) ⇒ LayergroupConfig

Returns a new instance of LayergroupConfig.



6
7
8
9
10
11
12
# File 'lib/geoserver_migrations/layergroup_config.rb', line 6

def initialize(layer_name, is_update_style=false)
  @options = {
      layer_name: layer_name,
      is_update_style: is_update_style,
      layers: []
  }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/geoserver_migrations/layergroup_config.rb', line 33

def method_missing(method,*args,&block)
  # puts "LayerConfig method-missing: #{method.inspect}, #{args.inspect}"
  if [:layer_name].include? method.to_sym
    if args.size > 0
      value = args.size == 1 ? args.first : args
      value = value.strip if value.is_a? String
      @options[method.to_sym] = value
    else
      @options[method.to_sym]
    end
  else
    super
  end
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/geoserver_migrations/layergroup_config.rb', line 4

def options
  @options
end

Instance Method Details

#layers(*received_layers) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/geoserver_migrations/layergroup_config.rb', line 19

def layers(*received_layers)
  if received_layers.nil?
    @options[:layers]
  else
    if received_layers.is_a? String
      @options[:layers] = received_layers.split(/[,; ]/).select{|x| !x.empty?}
    elsif received_layers.is_a? Array
      received_layers.each do |received_layer|
        @options[:layers] += received_layer.split(/[,; ]/).select{|x| !x.empty?}
      end   
    end           
  end
end

#valid?Boolean

Returns:

  • (Boolean)


14
15
16
17
# File 'lib/geoserver_migrations/layergroup_config.rb', line 14

def valid?
  # at least one layer to be grouped should be present?
  options[:layers].size > 0
end