xhive 1.2.0.pre → 1.2.1.pre

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.
@@ -38,11 +38,23 @@ module Xhive
38
38
  #
39
39
  def self.map_resource(site, page, resource, action, key = nil)
40
40
  mapper = find_map(site, resource, action, key)
41
- mapper = new(:site_id => site.id, :resource => resource, :action => action, :key => key) unless mapper.present?
41
+ mapper = new(:site_id => site.id, :resource => resource,
42
+ :action => action, :key => key.present? ? key : nil) unless mapper.present?
42
43
  mapper.page = page
43
44
  mapper.save
44
45
  end
45
46
 
47
+ # Public: returns all the mappers for a specific resource.
48
+ #
49
+ # site - The Site owner of the mappers.
50
+ # resource - The String containing the resource to filter by.
51
+ #
52
+ # Returns: an ActiveRecord::Relation filtered by resource.
53
+ #
54
+ def self.all_by_resource(site, resource)
55
+ where(:site_id => site.id).where(:resource => resource)
56
+ end
57
+
46
58
  private
47
59
 
48
60
  # Private: looks for a mapper object.
@@ -55,8 +67,10 @@ module Xhive
55
67
  # Returns: the mapper object or nil if not found.
56
68
  #
57
69
  def self.find_map(site, resource, action, key)
58
- mapper = where(:site_id => site.id).where(:resource => resource).where(:action => action)
59
- mapper = mapper.where(:key => key) if key.present?
70
+ mapper = where(:site_id => site.id)
71
+ mapper = mapper.where(:resource => resource)
72
+ mapper = mapper.where(:action => action)
73
+ mapper = mapper.where(:key => key.present? ? key : nil)
60
74
  mapper.first
61
75
  end
62
76
  end
data/lib/xhive/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Xhive
2
- VERSION = "1.2.0.pre"
2
+ VERSION = "1.2.1.pre"
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.2.0.pre
4
+ version: 1.2.1.pre
5
5
  prerelease: 6
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: 2012-11-13 00:00:00.000000000 Z
12
+ date: 2012-11-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -297,7 +297,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
297
297
  version: '0'
298
298
  segments:
299
299
  - 0
300
- hash: -4002595324166210209
300
+ hash: 2967828758709563627
301
301
  required_rubygems_version: !ruby/object:Gem::Requirement
302
302
  none: false
303
303
  requirements: