relaxo-model 0.3.6 → 0.3.8

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.
@@ -66,29 +66,19 @@ module Relaxo
66
66
  # This reduction returns a single result, so just provide the first row directly:
67
67
  reduction = options.delete(:reduction)
68
68
 
69
- # Specify a composite key, e.g. :key => :self or :key => [:self]
70
- if key = options[:key]
71
- options = options.dup
72
-
73
- if key == :self
74
- options[:key] = lambda do |object, query|
75
- query[:key] = object.id
76
- end
77
- elsif Array === key
78
- index = key.index(:self)
79
-
80
- options[:key] = lambda do |object, query|
81
- query[:key] = key.dup
82
- query[:key][index] = object.id
83
- end
84
- end
85
- end
69
+ options = options.dup
70
+
71
+ update_key_function(options, :key)
72
+ update_key_function(options, :startkey)
73
+ update_key_function(options, :endkey)
86
74
 
87
75
  self.send(:define_method, name) do |query = {}|
88
76
  query = query.merge(options)
89
77
 
90
- if options[:key].respond_to? :call
91
- options[:key].call(self, query)
78
+ [:key, :startkey, :endkey].each do |name|
79
+ if options[name].respond_to? :call
80
+ options[name].call(self, query)
81
+ end
92
82
  end
93
83
 
94
84
  recordset = Recordset.new(@database, @database.view(path, query), klass)
@@ -138,6 +128,26 @@ module Relaxo
138
128
  end
139
129
  end
140
130
  end
131
+
132
+ private
133
+
134
+ # Used for generating key functions for relationships - subject to change so private for now.
135
+ def update_key_function(options, name)
136
+ key = options[name]
137
+
138
+ if key == :self
139
+ options[name] = lambda do |object, query|
140
+ query[name] = object.id
141
+ end
142
+ elsif Array === key
143
+ index = key.index(:self)
144
+
145
+ options[name] = lambda do |object, query|
146
+ query[name] = key.dup
147
+ query[name][index] = object.id
148
+ end
149
+ end
150
+ end
141
151
  end
142
152
  end
143
153
  end
@@ -0,0 +1,43 @@
1
+ # Copyright (c) 2012 Samuel G. D. Williams. <http://www.oriontransfer.co.nz>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require 'bcrypt'
22
+
23
+ module Relaxo
24
+ module Model
25
+ module Properties
26
+ Attribute.for_class(BCrypt::Password) do
27
+ def convert_to_primative(value)
28
+ [value.salt, value.checksum]
29
+ end
30
+
31
+ def convert_from_primative(database, value)
32
+ if String === value
33
+ # If the primative value is a string, we are saving the password:
34
+ BCrypt::Password.create(value)
35
+ else
36
+ # Otherwise the password is given by an array containing the salt and checksum:
37
+ BCrypt::Password.new(value.join)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -23,7 +23,7 @@ module Relaxo
23
23
  module VERSION
24
24
  MAJOR = 0
25
25
  MINOR = 3
26
- TINY = 6
26
+ TINY = 8
27
27
 
28
28
  STRING = [MAJOR, MINOR, TINY].join('.')
29
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaxo-model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.8
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: 2012-07-29 00:00:00.000000000 Z
12
+ date: 2012-07-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: relaxo
@@ -53,6 +53,7 @@ files:
53
53
  - lib/relaxo/model/component.rb
54
54
  - lib/relaxo/model/document.rb
55
55
  - lib/relaxo/model/properties/attribute.rb
56
+ - lib/relaxo/model/properties/bcrypt.rb
56
57
  - lib/relaxo/model/properties/bigdecimal.rb
57
58
  - lib/relaxo/model/properties/composite.rb
58
59
  - lib/relaxo/model/properties/latinum.rb