class RGeoServer::ResourceInfo
Constants
- OBJ_ATTRIBUTES
mapping object parameters to profile elements
- OBJ_DEFAULT_ATTRIBUTES
Attributes
Public Class Methods
Generic object construction iterator @param [RGeoServer::ResourceInfo.class] klass @param [RGeoServer::Catalog] catalog @param [Array<String>] names @param [Hash] options @param [bool] check_remote if already exists in catalog and cache it @yield [RGeoServer::ResourceInfo,klass] optional
# File lib/rgeoserver/resource.rb, line 42 def self.list klass, catalog, names, options = {}, check_remote = false raise ArgumentError, "Names required" if names.nil? names = [names] unless names.is_a? Array l = [] unless block_given? names.each do |name| obj = klass.new catalog, options.merge(:name => name) obj.new? if check_remote if block_given? yield obj else l << obj end end l unless block_given? end
# File lib/rgeoserver/resource.rb, line 58 def initialize catalog = nil @new = true @catalog = catalog end
# File lib/rgeoserver/resource.rb, line 20 def self.update_attribute_accessors attributes attributes.each do |attribute, profile_name| class_eval <<-RUBY def #{attribute.to_s} @#{attribute} || profile['#{profile_name.to_s}'] || OBJ_DEFAULT_ATTRIBUTES[:#{attribute}] end def #{attribute.to_s}= val #{attribute.to_s}_will_change! unless val == #{attribute.to_s} @#{attribute.to_s} = val end RUBY end end
Public Instance Methods
# File lib/rgeoserver/resource.rb, line 134 def clear @profile = nil @changed_attributes = {} end
# File lib/rgeoserver/resource.rb, line 67 def create_method :post end
Purge resource from Geoserver Catalog
@param [Hash] options @return [RGeoServer::ResourceInfo] `self`
# File lib/rgeoserver/resource.rb, line 119 def delete options = {} run_callbacks :destroy do @catalog.purge({@route => @name}, options) unless new? clear self end end
Check if this resource already exists @return [Boolean]
# File lib/rgeoserver/resource.rb, line 129 def new? profile @new end
Retrieve the resource profile as a hash and cache it @return [Hash]
# File lib/rgeoserver/resource.rb, line 147 def profile unless @profile begin self.profile = @catalog.search @route => @name @new = false rescue RestClient::ResourceNotFound # The resource is new @profile = {} @new = true end @profile.freeze unless @profile.frozen? end @profile end
# File lib/rgeoserver/resource.rb, line 161 def profile= profile_xml @profile = profile_xml_to_hash(profile_xml) @profile.freeze end
# File lib/rgeoserver/resource.rb, line 170 def profile_xml_to_hash profile_xml raise NotImplementedError, 'profile_xml_to_hash is abstract method' end
# File lib/rgeoserver/resource.rb, line 166 def profile_xml_to_ng profile_xml Nokogiri::XML(profile_xml).xpath(self.class.member_xpath) end
# File lib/rgeoserver/resource.rb, line 139 def refresh clear profile self end
Modify or save the resource @param [Hash] options / query parameters @return [RGeoServer::ResourceInfo]
# File lib/rgeoserver/resource.rb, line 84 def save options = {} @previously_changed = changes @changed_attributes.clear run_callbacks :save do unless @previously_changed[:name].nil? old_name, new_name = @previously_changed[:name] name_route = old_name if old_name != new_name update = true else name_route = name update = false end if !update && new? if self.respond_to?(:create_route) raise "Resource cannot be created directly" if create_route.nil? route = create_route else route = {@route => nil} end options = create_options.merge(options) if self.respond_to?(:create_options) @catalog.add(route, message, create_method, options) clear else options = update_params(name_route).merge(options) route = {@route => name_route} @catalog.modify(route, message, update_method, options) #unless changes.empty? end self end end
# File lib/rgeoserver/resource.rb, line 63 def to_s "#{self.class.name}: #{name} (#{new?}) on #{catalog}" end
# File lib/rgeoserver/resource.rb, line 71 def update_method :put end
We pass the old name “name_route” in case the name of the resource is being edited Child classes should implement this
# File lib/rgeoserver/resource.rb, line 77 def update_params name_route = name { self.class.resource_name.downcase.to_sym => name_route } end