Class: RGeoServer::ResourceInfo
- Inherits:
-
Object
- Object
- RGeoServer::ResourceInfo
- Extended by:
- ActiveModel::Callbacks
- Includes:
- ActiveModel::Dirty
- Defined in:
- lib/rgeoserver/resource.rb
Direct Known Subclasses
Coverage, CoverageStore, DataStore, FeatureType, Layer, LayerGroup, Namespace, Style, WmsStore, Workspace
Constant Summary collapse
- OBJ_ATTRIBUTES =
mapping object parameters to profile elements
{:enabled => 'enabled'}
- OBJ_DEFAULT_ATTRIBUTES =
{:enabled => 'true'}
Instance Attribute Summary collapse
-
#catalog ⇒ Object
Returns the value of attribute catalog.
Class Method Summary collapse
-
.list(klass, catalog, names, options = {}, check_remote = false) {|RGeoServer::ResourceInfo, klass| ... } ⇒ Object
Generic object construction iterator.
- .update_attribute_accessors(attributes) ⇒ Object
Instance Method Summary collapse
- #clear ⇒ Object
- #create_method ⇒ Object
-
#delete(options = {}) ⇒ RGeoServer::ResourceInfo
Purge resource from Geoserver Catalog.
-
#initialize(catalog = nil) ⇒ ResourceInfo
constructor
A new instance of ResourceInfo.
-
#new? ⇒ Boolean
Check if this resource already exists.
-
#profile ⇒ Hash
Retrieve the resource profile as a hash and cache it.
- #profile=(profile_xml) ⇒ Object
- #profile_xml_to_hash(profile_xml) ⇒ Object
- #profile_xml_to_ng(profile_xml) ⇒ Object
- #refresh ⇒ Object
-
#save(options = {}) ⇒ RGeoServer::ResourceInfo
Modify or save the resource.
- #to_s ⇒ Object
- #update_method ⇒ Object
-
#update_params(name_route = name) ⇒ Object
We pass the old name “name_route” in case the name of the resource is being edited Child classes should implement this.
Constructor Details
#initialize(catalog = nil) ⇒ ResourceInfo
Returns a new instance of ResourceInfo.
58 59 60 61 |
# File 'lib/rgeoserver/resource.rb', line 58 def initialize catalog = nil @new = true @catalog = catalog end |
Instance Attribute Details
#catalog ⇒ Object
Returns the value of attribute catalog.
12 13 14 |
# File 'lib/rgeoserver/resource.rb', line 12 def catalog @catalog end |
Class Method Details
.list(klass, catalog, names, options = {}, check_remote = false) {|RGeoServer::ResourceInfo, klass| ... } ⇒ Object
Generic object construction iterator
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rgeoserver/resource.rb', line 42 def self.list klass, catalog, names, = {}, 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, .merge(:name => name) obj.new? if check_remote if block_given? yield obj else l << obj end end l unless block_given? end |
.update_attribute_accessors(attributes) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# 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 |
Instance Method Details
#clear ⇒ Object
134 135 136 137 |
# File 'lib/rgeoserver/resource.rb', line 134 def clear @profile = nil @changed_attributes = {} end |
#create_method ⇒ Object
67 68 69 |
# File 'lib/rgeoserver/resource.rb', line 67 def create_method :post end |
#delete(options = {}) ⇒ RGeoServer::ResourceInfo
Purge resource from Geoserver Catalog
119 120 121 122 123 124 125 |
# File 'lib/rgeoserver/resource.rb', line 119 def delete = {} run_callbacks :destroy do @catalog.purge({@route => @name}, ) unless new? clear self end end |
#new? ⇒ Boolean
Check if this resource already exists
129 130 131 132 |
# File 'lib/rgeoserver/resource.rb', line 129 def new? profile @new end |
#profile ⇒ Hash
Retrieve the resource profile as a hash and cache it
147 148 149 150 151 152 153 154 155 156 157 158 159 |
# 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 |
#profile=(profile_xml) ⇒ Object
161 162 163 164 |
# File 'lib/rgeoserver/resource.rb', line 161 def profile= profile_xml @profile = profile_xml_to_hash(profile_xml) @profile.freeze end |
#profile_xml_to_hash(profile_xml) ⇒ Object
170 171 172 |
# File 'lib/rgeoserver/resource.rb', line 170 def profile_xml_to_hash profile_xml raise NotImplementedError, 'profile_xml_to_hash is abstract method' end |
#profile_xml_to_ng(profile_xml) ⇒ Object
166 167 168 |
# File 'lib/rgeoserver/resource.rb', line 166 def profile_xml_to_ng profile_xml Nokogiri::XML(profile_xml).xpath(self.class.member_xpath) end |
#refresh ⇒ Object
139 140 141 142 143 |
# File 'lib/rgeoserver/resource.rb', line 139 def refresh clear profile self end |
#save(options = {}) ⇒ RGeoServer::ResourceInfo
Modify or save the resource
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/rgeoserver/resource.rb', line 84 def save = {} @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 = .merge() if self.respond_to?(:create_options) @catalog.add(route, , create_method, ) clear else = update_params(name_route).merge() route = {@route => name_route} @catalog.modify(route, , update_method, ) #unless changes.empty? end self end end |
#to_s ⇒ Object
63 64 65 |
# File 'lib/rgeoserver/resource.rb', line 63 def to_s "#{self.class.name}: #{name} (#{new?}) on #{catalog}" end |
#update_method ⇒ Object
71 72 73 |
# File 'lib/rgeoserver/resource.rb', line 71 def update_method :put end |
#update_params(name_route = name) ⇒ Object
We pass the old name “name_route” in case the name of the resource is being edited Child classes should implement this
77 78 79 |
# File 'lib/rgeoserver/resource.rb', line 77 def update_params name_route = name { self.class.resource_name.downcase.to_sym => name_route } end |