xhive 1.6.6 → 1.6.7

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.
@@ -49,6 +49,24 @@ module Xhive
49
49
  mapper.save
50
50
  end
51
51
 
52
+ # Public: deletes a mapper for a specific resource.
53
+ #
54
+ # site - The Site to associate the mapper to.
55
+ # resource - The String containing the associated resource name.
56
+ # action - The String containing the associated action name.
57
+ # key - The String containing the associated key.
58
+ # policy - The String containing the policy class.
59
+ #
60
+ # Returns: true if created. False otherwise.
61
+ #
62
+ def self.unmap_resource(site, resource, action, key = nil, policy = nil)
63
+ check_policy_class(policy) if policy.present?
64
+
65
+ mapper = find_exact_map(site, resource, action, key, policy)
66
+
67
+ mapper.delete if mapper.present?
68
+ end
69
+
52
70
  # Public: returns all the mappers for a specific resource.
53
71
  #
54
72
  # site - The Site owner of the mappers.
@@ -5,29 +5,43 @@ module Xhive
5
5
  module ClassMethods
6
6
  def mount_page(attr)
7
7
  # Define getter
8
- define_method(attr.to_s) do
8
+ mount_page_getter(attr.to_s)
9
+
10
+ # Define setter
11
+ mount_page_setter(attr)
12
+
13
+ # Define content
14
+ define_method("#{attr}_content") do |opts={}|
15
+ self.send(attr.to_sym).present_content(opts.merge({self.class.name.downcase.to_sym => self}))
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def mount_page_getter(attr)
22
+ define_method(attr) do
9
23
  # TODO: support multiple sites
10
24
  site = Xhive::Site.first
11
25
  begin
12
- page = Xhive::Mapper.page_for(site, self.class.name.downcase, attr.to_s, id)
26
+ page = Xhive::Mapper.page_for(site, self.class.name.downcase, attr.to_s, self.id)
13
27
  rescue ActiveRecord::RecordNotFound
14
28
  page = nil
15
29
  end
16
30
  return page
17
31
  end
32
+ end
18
33
 
19
- # Define setter
34
+ def mount_page_setter(attr)
20
35
  define_method("#{attr}=") do |value|
21
36
  fail RecordNotPersistedError, "Cannot assign a page to an unsaved #{self.class.name}" if new_record?
22
37
  # TODO: support multiple sites
23
38
  site = Xhive::Site.first
24
- page = value.is_a?(Xhive::Page) ? value : site.pages.find(value)
25
- Xhive::Mapper.map_resource(site, page, self.class.name.downcase, attr.to_s, id)
26
- end
27
-
28
- # Define content
29
- define_method("#{attr}_content") do |opts={}|
30
- self.send(attr.to_sym).present_content(opts.merge({self.class.name.downcase.to_sym => self}))
39
+ unless value.nil?
40
+ page = value.is_a?(Xhive::Page) ? value : site.pages.find(value)
41
+ Xhive::Mapper.map_resource(site, page, self.class.name.downcase, attr.to_s, self.id)
42
+ else
43
+ Xhive::Mapper.unmap_resource(site, self.class.name.downcase, attr.to_s, self.id)
44
+ end
31
45
  end
32
46
  end
33
47
  end
@@ -1,3 +1,3 @@
1
1
  module Xhive
2
- VERSION = "1.6.6"
2
+ VERSION = "1.6.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xhive
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.6
4
+ version: 1.6.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-06 00:00:00.000000000 Z
12
+ date: 2013-02-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -285,7 +285,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
285
285
  version: '0'
286
286
  segments:
287
287
  - 0
288
- hash: -1571194282988339322
288
+ hash: -3766204056813361461
289
289
  required_rubygems_version: !ruby/object:Gem::Requirement
290
290
  none: false
291
291
  requirements:
@@ -294,7 +294,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
294
294
  version: '0'
295
295
  segments:
296
296
  - 0
297
- hash: -1571194282988339322
297
+ hash: -3766204056813361461
298
298
  requirements: []
299
299
  rubyforge_project:
300
300
  rubygems_version: 1.8.21