dm-is-remixable 1.1.0.rc2 → 1.1.0.rc3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/VERSION +1 -1
- data/dm-is-remixable.gemspec +12 -12
- data/lib/dm-is-remixable/is/remixable.rb +43 -38
- data/lib/dm-is-remixable.rb +0 -6
- metadata +6 -6
data/Gemfile
CHANGED
@@ -5,7 +5,7 @@ source 'http://rubygems.org'
|
|
5
5
|
SOURCE = ENV.fetch('SOURCE', :git).to_sym
|
6
6
|
REPO_POSTFIX = SOURCE == :path ? '' : '.git'
|
7
7
|
DATAMAPPER = SOURCE == :path ? Pathname(__FILE__).dirname.parent : 'http://github.com/datamapper'
|
8
|
-
DM_VERSION = '~> 1.1.0.
|
8
|
+
DM_VERSION = '~> 1.1.0.rc3'
|
9
9
|
DO_VERSION = '~> 0.10.2'
|
10
10
|
DM_DO_ADAPTERS = %w[ sqlite postgres mysql oracle sqlserver ]
|
11
11
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.0.
|
1
|
+
1.1.0.rc3
|
data/dm-is-remixable.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{dm-is-remixable}
|
8
|
-
s.version = "1.1.0.
|
8
|
+
s.version = "1.1.0.rc3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Cory O'Daniel"]
|
12
|
-
s.date = %q{2011-03-
|
12
|
+
s.date = %q{2011-03-10}
|
13
13
|
s.description = %q{dm-is-remixable allow you to create reusable data functionality}
|
14
14
|
s.email = %q{dm-is-remixable [a] coryodaniel [d] com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -49,7 +49,7 @@ Gem::Specification.new do |s|
|
|
49
49
|
s.homepage = %q{http://github.com/datamapper/dm-is-remixable}
|
50
50
|
s.require_paths = ["lib"]
|
51
51
|
s.rubyforge_project = %q{datamapper}
|
52
|
-
s.rubygems_version = %q{1.
|
52
|
+
s.rubygems_version = %q{1.6.2}
|
53
53
|
s.summary = %q{dm-is-remixable allow you to create reusable data functionality}
|
54
54
|
s.test_files = [
|
55
55
|
"spec/data/addressable.rb",
|
@@ -73,24 +73,24 @@ Gem::Specification.new do |s|
|
|
73
73
|
s.specification_version = 3
|
74
74
|
|
75
75
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
76
|
-
s.add_runtime_dependency(%q<dm-core>, ["~> 1.1.0.
|
77
|
-
s.add_development_dependency(%q<dm-validations>, ["~> 1.1.0.
|
78
|
-
s.add_development_dependency(%q<dm-types>, ["~> 1.1.0.
|
76
|
+
s.add_runtime_dependency(%q<dm-core>, ["~> 1.1.0.rc3"])
|
77
|
+
s.add_development_dependency(%q<dm-validations>, ["~> 1.1.0.rc3"])
|
78
|
+
s.add_development_dependency(%q<dm-types>, ["~> 1.1.0.rc3"])
|
79
79
|
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
80
80
|
s.add_development_dependency(%q<rake>, ["~> 0.8.7"])
|
81
81
|
s.add_development_dependency(%q<rspec>, ["~> 1.3.1"])
|
82
82
|
else
|
83
|
-
s.add_dependency(%q<dm-core>, ["~> 1.1.0.
|
84
|
-
s.add_dependency(%q<dm-validations>, ["~> 1.1.0.
|
85
|
-
s.add_dependency(%q<dm-types>, ["~> 1.1.0.
|
83
|
+
s.add_dependency(%q<dm-core>, ["~> 1.1.0.rc3"])
|
84
|
+
s.add_dependency(%q<dm-validations>, ["~> 1.1.0.rc3"])
|
85
|
+
s.add_dependency(%q<dm-types>, ["~> 1.1.0.rc3"])
|
86
86
|
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
87
87
|
s.add_dependency(%q<rake>, ["~> 0.8.7"])
|
88
88
|
s.add_dependency(%q<rspec>, ["~> 1.3.1"])
|
89
89
|
end
|
90
90
|
else
|
91
|
-
s.add_dependency(%q<dm-core>, ["~> 1.1.0.
|
92
|
-
s.add_dependency(%q<dm-validations>, ["~> 1.1.0.
|
93
|
-
s.add_dependency(%q<dm-types>, ["~> 1.1.0.
|
91
|
+
s.add_dependency(%q<dm-core>, ["~> 1.1.0.rc3"])
|
92
|
+
s.add_dependency(%q<dm-validations>, ["~> 1.1.0.rc3"])
|
93
|
+
s.add_dependency(%q<dm-types>, ["~> 1.1.0.rc3"])
|
94
94
|
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
95
95
|
s.add_dependency(%q<rake>, ["~> 0.8.7"])
|
96
96
|
s.add_dependency(%q<rspec>, ["~> 1.3.1"])
|
@@ -1,25 +1,12 @@
|
|
1
1
|
require 'dm-core'
|
2
|
+
require 'dm-core/support/inflector'
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
rescue
|
6
|
-
require 'extlib/inflection'
|
7
|
-
class String
|
8
|
-
def underscore
|
9
|
-
Extlib::Inflection.underscore(self)
|
10
|
-
end
|
4
|
+
module DataMapper::Ext::Object
|
5
|
+
def self.full_const_defined?(obj, name = nil)
|
6
|
+
!!self.full_const_get(obj, name) rescue false
|
11
7
|
end
|
12
8
|
end
|
13
9
|
|
14
|
-
# reopen datamapper/extlib/lib/extlib/object.rb
|
15
|
-
class Object
|
16
|
-
|
17
|
-
def full_const_defined?(name)
|
18
|
-
!!full_const_get(name) rescue false
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
10
|
module DataMapper
|
24
11
|
module Is
|
25
12
|
module Remixable
|
@@ -68,7 +55,10 @@ module DataMapper
|
|
68
55
|
@is_remixable = true
|
69
56
|
|
70
57
|
# support clean suffixes for nested modules
|
71
|
-
|
58
|
+
inflector = DataMapper::Inflector
|
59
|
+
default_suffix = inflector.demodulize(self.name)
|
60
|
+
default_suffix = inflector.singularize(default_suffix)
|
61
|
+
default_suffix = inflector.underscore(default_suffix)
|
72
62
|
suffix(options.delete(:suffix) || default_suffix)
|
73
63
|
end
|
74
64
|
|
@@ -157,8 +147,8 @@ module DataMapper
|
|
157
147
|
# Example (from my upcoming dm-is-rateable gem)
|
158
148
|
# remix n, "DataMapper::Is::Rateable::Rating", :as => :ratings
|
159
149
|
remixable_module = case remixable
|
160
|
-
when Symbol then Object.full_const_get(DataMapper::Inflector.classify(remixable))
|
161
|
-
when String then Object.full_const_get(remixable)
|
150
|
+
when Symbol then DataMapper::Ext::Object.full_const_get(Object, DataMapper::Inflector.classify(remixable))
|
151
|
+
when String then DataMapper::Ext::Object.full_const_get(Object, remixable)
|
162
152
|
when Module then remixable
|
163
153
|
end
|
164
154
|
|
@@ -171,10 +161,14 @@ module DataMapper
|
|
171
161
|
options[:model] = options.delete(:class_name)
|
172
162
|
end
|
173
163
|
|
164
|
+
inflector = DataMapper::Inflector
|
165
|
+
model = inflector.underscore(self.name)
|
166
|
+
model = inflector.camelize(model + '_' + remixable_module.suffix)
|
167
|
+
|
174
168
|
#Merge defaults/options
|
175
169
|
options = {
|
176
170
|
:as => nil,
|
177
|
-
:model =>
|
171
|
+
:model => model,
|
178
172
|
:for => nil,
|
179
173
|
:on => nil,
|
180
174
|
:unique => false,
|
@@ -183,10 +177,10 @@ module DataMapper
|
|
183
177
|
}.update(options)
|
184
178
|
|
185
179
|
#Make sure the class hasn't been remixed already
|
186
|
-
unless Object.full_const_defined?(
|
180
|
+
unless DataMapper::Ext::Object.full_const_defined?(inflector.classify(options[:model]))
|
187
181
|
|
188
182
|
#Storage name of our remixed model
|
189
|
-
options[:table_name] = DataMapper::Inflector.tableize(
|
183
|
+
options[:table_name] = DataMapper::Inflector.tableize(inflector.demodulize(options[:model]))
|
190
184
|
|
191
185
|
#Other model to mix with in case of M:M through Remixable
|
192
186
|
options[:other_model] = options[:for] || options[:on]
|
@@ -197,16 +191,17 @@ module DataMapper
|
|
197
191
|
# map the remixable to the remixed model
|
198
192
|
# since this will be used from 'enhance api' i think it makes perfect sense to
|
199
193
|
# always refer to a remixable by its demodulized underscored constant name
|
200
|
-
remixable_key =
|
194
|
+
remixable_key = inflector.demodulize(remixable_module.name)
|
195
|
+
remixable_key = inflector.underscore(remixable_key).to_sym
|
201
196
|
populate_remixables_mapping(model, options.merge(:remixable_key => remixable_key))
|
202
197
|
|
203
198
|
# attach RemixerClassMethods and RemixerInstanceMethods to remixer if defined by remixee
|
204
|
-
if Object.full_const_defined? "#{remixable_module}::RemixerClassMethods"
|
205
|
-
extend Object.full_const_get("#{remixable_module}::RemixerClassMethods")
|
199
|
+
if DataMapper::Ext::Object.full_const_defined? "#{remixable_module}::RemixerClassMethods"
|
200
|
+
extend DataMapper::Ext::Object.full_const_get("#{remixable_module}::RemixerClassMethods")
|
206
201
|
end
|
207
202
|
|
208
|
-
if Object.full_const_defined? "#{remixable_module}::RemixerInstanceMethods"
|
209
|
-
include Object.full_const_get("#{remixable_module}::RemixerInstanceMethods")
|
203
|
+
if DataMapper::Ext::Object.full_const_defined? "#{remixable_module}::RemixerInstanceMethods"
|
204
|
+
include DataMapper::Ext::Object.full_const_get("#{remixable_module}::RemixerInstanceMethods")
|
210
205
|
end
|
211
206
|
|
212
207
|
#Create relationships between Remixer and remixed class
|
@@ -264,12 +259,16 @@ module DataMapper
|
|
264
259
|
# belongs_to :tag
|
265
260
|
# end
|
266
261
|
def enhance(remixable,remixable_model=nil, &block)
|
262
|
+
inflector = DataMapper::Inflector
|
263
|
+
|
267
264
|
# always use innermost singular underscored constant name
|
268
|
-
remixable_name = remixable.to_s
|
265
|
+
remixable_name = inflector.singularize(remixable.to_s)
|
266
|
+
remixable_name = inflector.underscore(remixable_name).to_sym
|
269
267
|
class_name = if remixable_model.nil?
|
270
268
|
@remixables[remixable_name].keys.first
|
271
269
|
else
|
272
|
-
|
270
|
+
name = inflector.demodulize(remixable_model.to_s)
|
271
|
+
inflector.underscore(name).to_sym
|
273
272
|
end
|
274
273
|
|
275
274
|
model = @remixables[remixable_name][class_name][:model] unless @remixables[remixable_name][class_name].nil?
|
@@ -293,7 +292,11 @@ module DataMapper
|
|
293
292
|
key = options[:remixable_key]
|
294
293
|
accessor_name = options[:as] ? options[:as] : options[:table_name]
|
295
294
|
@remixables[key] ||= {}
|
296
|
-
|
295
|
+
|
296
|
+
inflector = DataMapper::Inflector
|
297
|
+
model_key = inflector.demodulize(remixable_model.to_s)
|
298
|
+
model_key = inflector.underscore(model_key).to_sym
|
299
|
+
|
297
300
|
@remixables[key][model_key] ||= {}
|
298
301
|
@remixables[key][model_key][:reader] ||= accessor_name.to_sym
|
299
302
|
@remixables[key][model_key][:writer] ||= "#{accessor_name}=".to_sym
|
@@ -321,7 +324,7 @@ module DataMapper
|
|
321
324
|
# model <Class> remixed model that 'self' is relating through
|
322
325
|
# options <Hash> options hash
|
323
326
|
def remix_many_to_many(cardinality, model, options)
|
324
|
-
options[:other_model] = Object.full_const_get(DataMapper::Inflector.classify(options[:other_model]))
|
327
|
+
options[:other_model] = DataMapper::Ext::Object.full_const_get(DataMapper::Inflector.classify(options[:other_model]))
|
325
328
|
|
326
329
|
#TODO if options[:unique] the two *_id's need to be a unique composite key, maybe even
|
327
330
|
# attach a validates_is_unique if the validator is included.
|
@@ -362,7 +365,7 @@ module DataMapper
|
|
362
365
|
# TODO clean this up!
|
363
366
|
parts = options[:model].split('::')
|
364
367
|
name = parts.last
|
365
|
-
namespace = Object.full_const_get((parts - [name]).join('::'))
|
368
|
+
namespace = DataMapper::Ext::Object.full_const_get((parts - [name]).join('::'))
|
366
369
|
|
367
370
|
model = Model.new(name, namespace) do
|
368
371
|
include remixable
|
@@ -385,12 +388,12 @@ module DataMapper
|
|
385
388
|
end
|
386
389
|
|
387
390
|
# Attach remixed model access to RemixeeClassMethods and RemixeeInstanceMethods if defined
|
388
|
-
if Object.full_const_defined? "#{remixable}::RemixeeClassMethods"
|
389
|
-
model.send :extend, Object.full_const_get("#{remixable}::RemixeeClassMethods")
|
391
|
+
if DataMapper::Ext::Object.full_const_defined? "#{remixable}::RemixeeClassMethods"
|
392
|
+
model.send :extend, DataMapper::Ext::Object.full_const_get("#{remixable}::RemixeeClassMethods")
|
390
393
|
end
|
391
394
|
|
392
|
-
if Object.full_const_defined? "#{remixable}::RemixeeInstanceMethods"
|
393
|
-
model.send :include, Object.full_const_get("#{remixable}::RemixeeInstanceMethods")
|
395
|
+
if DataMapper::Ext::Object.full_const_defined? "#{remixable}::RemixeeInstanceMethods"
|
396
|
+
model.send :include, DataMapper::Ext::Object.full_const_get("#{remixable}::RemixeeInstanceMethods")
|
394
397
|
end
|
395
398
|
|
396
399
|
clone_hooks(remixable, model)
|
@@ -399,7 +402,9 @@ module DataMapper
|
|
399
402
|
end
|
400
403
|
|
401
404
|
def belongs_to_name(class_name)
|
402
|
-
DataMapper::Inflector.demodulize(class_name)
|
405
|
+
name = DataMapper::Inflector.demodulize(class_name)
|
406
|
+
name = DataMapper::Inflector.underscore(name)
|
407
|
+
name.gsub(/\//, '_').to_sym
|
403
408
|
end
|
404
409
|
|
405
410
|
private
|
data/lib/dm-is-remixable.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: dm-is-remixable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease: 6
|
5
|
-
version: 1.1.0.
|
5
|
+
version: 1.1.0.rc3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Cory O'Daniel
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-03-
|
13
|
+
date: 2011-03-10 00:00:00 -08:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ~>
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 1.1.0.
|
23
|
+
version: 1.1.0.rc3
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
26
|
version_requirements: *id001
|
@@ -31,7 +31,7 @@ dependencies:
|
|
31
31
|
requirements:
|
32
32
|
- - ~>
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: 1.1.0.
|
34
|
+
version: 1.1.0.rc3
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: *id002
|
@@ -42,7 +42,7 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 1.1.0.
|
45
|
+
version: 1.1.0.rc3
|
46
46
|
type: :development
|
47
47
|
prerelease: false
|
48
48
|
version_requirements: *id003
|
@@ -141,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
141
|
requirements: []
|
142
142
|
|
143
143
|
rubyforge_project: datamapper
|
144
|
-
rubygems_version: 1.
|
144
|
+
rubygems_version: 1.6.2
|
145
145
|
signing_key:
|
146
146
|
specification_version: 3
|
147
147
|
summary: dm-is-remixable allow you to create reusable data functionality
|