perry 0.6.2 → 0.6.3
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.
- data/lib/perry.rb +0 -1
- data/lib/perry/base.rb +8 -5
- data/lib/perry/core_ext/kernel/singleton_class.rb +1 -0
- data/lib/perry/scopes.rb +11 -15
- data/lib/perry/serialization.rb +2 -2
- data/lib/perry/support/class_attributes.rb +48 -0
- data/lib/perry/version.rb +1 -1
- metadata +6 -5
data/lib/perry.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
# TRP: Cherry pick some goodies from active_support
|
2
2
|
require 'active_support/core_ext/array'
|
3
|
-
require 'active_support/core_ext/class/inheritable_attributes'
|
4
3
|
require 'active_support/core_ext/hash/deep_merge'
|
5
4
|
require 'active_support/core_ext/hash/keys'
|
6
5
|
require 'active_support/core_ext/hash/conversions'
|
data/lib/perry/base.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# TRP: Perry modules
|
2
|
+
require 'perry/support/class_attributes'
|
2
3
|
require 'perry/errors'
|
3
4
|
require 'perry/associations/contains'
|
4
5
|
require 'perry/associations/external'
|
@@ -8,6 +9,7 @@ require 'perry/scopes'
|
|
8
9
|
require 'perry/adapters'
|
9
10
|
|
10
11
|
class Perry::Base
|
12
|
+
include Perry::Support::ClassAttributes
|
11
13
|
include Perry::Associations::Contains
|
12
14
|
include Perry::Associations::External
|
13
15
|
include Perry::Serialization
|
@@ -20,11 +22,12 @@ class Perry::Base
|
|
20
22
|
alias :saved? :saved
|
21
23
|
alias :persisted? :saved?
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
+
class_attributes :read_adapter, :write_adapter
|
26
|
+
class_attributes :defined_attributes, :scoped_methods, :defined_associations, :scopes
|
25
27
|
|
26
28
|
self.defined_associations = {}
|
27
29
|
self.defined_attributes = []
|
30
|
+
self.scopes = {}
|
28
31
|
|
29
32
|
def initialize(attributes={})
|
30
33
|
self.new_record = true
|
@@ -127,7 +130,7 @@ class Perry::Base
|
|
127
130
|
|
128
131
|
def write_with(adapter_type)
|
129
132
|
if write_adapter
|
130
|
-
|
133
|
+
self.write_adapter = nil if adapter_type != write_adapter.type
|
131
134
|
else
|
132
135
|
# TRP: Pull in methods and libraries needed for mutable functionality
|
133
136
|
require 'perry/persistence' unless defined?(Perry::Persistence)
|
@@ -194,7 +197,7 @@ class Perry::Base
|
|
194
197
|
private
|
195
198
|
|
196
199
|
def setup_adapter(mode, config)
|
197
|
-
current_adapter =
|
200
|
+
current_adapter = self.send(:"#{mode}_adapter")
|
198
201
|
type = config[:type] if config.is_a?(Hash)
|
199
202
|
|
200
203
|
new_adapter = if type == :none
|
@@ -205,7 +208,7 @@ class Perry::Base
|
|
205
208
|
Perry::Adapters::AbstractAdapter.create(type, config)
|
206
209
|
end
|
207
210
|
|
208
|
-
|
211
|
+
self.send(:"#{mode}_adapter=", new_adapter)
|
209
212
|
end
|
210
213
|
|
211
214
|
def configure_adapter(mode, &block)
|
data/lib/perry/scopes.rb
CHANGED
@@ -1,20 +1,16 @@
|
|
1
1
|
require 'perry/scopes/conditions'
|
2
2
|
|
3
3
|
module Perry::Scopes
|
4
|
-
|
4
|
+
|
5
5
|
module ClassMethods
|
6
|
-
|
7
|
-
def scopes
|
8
|
-
read_inheritable_attribute(:scopes) || write_inheritable_attribute(:scopes, {})
|
9
|
-
end
|
10
|
-
|
6
|
+
|
11
7
|
def scoped
|
12
8
|
current_scope ? relation.merge(current_scope) : relation.clone
|
13
9
|
end
|
14
|
-
|
10
|
+
|
15
11
|
def scope(name, scope_options={})
|
16
12
|
name = name.to_sym
|
17
|
-
|
13
|
+
|
18
14
|
# TRP: Define the scope and merge onto the relation
|
19
15
|
scopes[name] = lambda do |*args|
|
20
16
|
options = scope_options.is_a?(Proc) ? scope_options.call(*args) : scope_options
|
@@ -24,22 +20,22 @@ module Perry::Scopes
|
|
24
20
|
scoped.merge(options)
|
25
21
|
end
|
26
22
|
end
|
27
|
-
|
23
|
+
|
28
24
|
# TRP: Bind the above block to a method for easy access
|
29
25
|
singleton_class.send(:define_method, name, &scopes[name])
|
30
26
|
end
|
31
|
-
|
27
|
+
|
32
28
|
end
|
33
|
-
|
29
|
+
|
34
30
|
module InstanceMethods
|
35
|
-
|
31
|
+
|
36
32
|
end
|
37
|
-
|
33
|
+
|
38
34
|
def self.included(receiver)
|
39
35
|
receiver.extend ClassMethods
|
40
36
|
receiver.send :include, InstanceMethods
|
41
|
-
|
37
|
+
|
42
38
|
receiver.extend Conditions
|
43
39
|
end
|
44
|
-
|
40
|
+
|
45
41
|
end
|
data/lib/perry/serialization.rb
CHANGED
@@ -37,7 +37,7 @@ module Perry::Serialization
|
|
37
37
|
|
38
38
|
def self.included(receiver)
|
39
39
|
receiver.class_eval do
|
40
|
-
|
40
|
+
class_attribute :serialized_attributes
|
41
41
|
self.serialized_attributes = []
|
42
42
|
end
|
43
43
|
|
@@ -45,4 +45,4 @@ module Perry::Serialization
|
|
45
45
|
receiver.send :include, InstanceMethods
|
46
46
|
end
|
47
47
|
|
48
|
-
end
|
48
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Perry::Support; end
|
2
|
+
|
3
|
+
module Perry::Support::ClassAttributes
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
base.extend ClassMethods
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
|
11
|
+
def class_attribute(*attrs)
|
12
|
+
@class_attributes ||= []
|
13
|
+
@class_attributes += attrs
|
14
|
+
attrs.each do |attr|
|
15
|
+
class_eval %{
|
16
|
+
def self.#{attr}
|
17
|
+
@#{attr}
|
18
|
+
end
|
19
|
+
def self.#{attr}=(value = nil)
|
20
|
+
@#{attr} = value
|
21
|
+
end
|
22
|
+
def #{attr}
|
23
|
+
self.class.#{attr}
|
24
|
+
end
|
25
|
+
def #{attr}=(value = nil)
|
26
|
+
self.class.#{attr} = value
|
27
|
+
end
|
28
|
+
}
|
29
|
+
end
|
30
|
+
@class_attributes
|
31
|
+
end
|
32
|
+
alias :class_attributes :class_attribute
|
33
|
+
|
34
|
+
def inherited(subclass)
|
35
|
+
(["class_attributes"] + class_attributes).each do |t|
|
36
|
+
ivar = "@#{t}"
|
37
|
+
value = instance_variable_get(ivar)
|
38
|
+
subclass.instance_variable_set(
|
39
|
+
ivar,
|
40
|
+
value.duplicable? ? value.dup : value
|
41
|
+
)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
data/lib/perry/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: perry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 1
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 6
|
9
|
-
-
|
10
|
-
version: 0.6.
|
9
|
+
- 3
|
10
|
+
version: 0.6.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Travis Petticrew
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-09-21 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: shoulda
|
@@ -168,6 +168,7 @@ files:
|
|
168
168
|
- lib/perry/scopes/conditions.rb
|
169
169
|
- lib/perry/scopes.rb
|
170
170
|
- lib/perry/serialization.rb
|
171
|
+
- lib/perry/support/class_attributes.rb
|
171
172
|
- lib/perry/version.rb
|
172
173
|
- lib/perry.rb
|
173
174
|
homepage: http://github.com/tpett/perry
|
@@ -200,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
200
201
|
requirements: []
|
201
202
|
|
202
203
|
rubyforge_project:
|
203
|
-
rubygems_version: 1.
|
204
|
+
rubygems_version: 1.8.9
|
204
205
|
signing_key:
|
205
206
|
specification_version: 3
|
206
207
|
summary: Ruby library for querying and mapping data through generic interfaces
|