dm-is-remixable 0.9.8 → 0.9.9

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/History.txt CHANGED
@@ -1,5 +1,18 @@
1
+ === 0.9.9 / 2009-01-04
2
+
3
+ * 1 bug fix:
4
+
5
+ * belongs_to association names are no longer made plural.
6
+
7
+ === 0.9.8 / 2008-12-07
8
+
9
+ * 2 minor enhancements:
10
+
11
+ * When using :as remixables ONLY create the given accessor instead of creating the default and aliasing it.
12
+ * Remixable Modules can now namespace methods to remixing classes and generated class.
13
+
1
14
  === 0.9.3 / 2008-07-31
2
15
 
3
- * 1 major enhancement
16
+ * 1 major enhancement:
4
17
 
5
18
  * Pre-Release, super beta.
data/Manifest.txt CHANGED
@@ -22,3 +22,5 @@ spec/data/viewable.rb
22
22
  spec/integration/remixable_spec.rb
23
23
  spec/spec.opts
24
24
  spec/spec_helper.rb
25
+ tasks/install.rb
26
+ tasks/spec.rb
data/README.txt CHANGED
@@ -133,38 +133,38 @@ modules are present the are attached appropriately to the other classes.
133
133
  module ExampleRemixable
134
134
  include DataMapper::Resource
135
135
  is :remixable
136
-
136
+
137
137
  #... your properies ...
138
-
138
+
139
139
  # Class methods that will be attached to class doing the remixing...
140
- #
140
+ #
141
141
  # These methods would be attached to the User class given:
142
142
  # User.remixes n, :images
143
- #
143
+ #
144
144
  module RemixerClassMethods
145
145
  end
146
-
146
+
147
147
  # Instances methods that will be attached to objects of the class doing the remixing...
148
- #
148
+ #
149
149
  # These methods would be attached to User objects given:
150
150
  # User.remixes n, :images
151
151
  #
152
152
  module RemixerInstanceMethods
153
153
  end
154
-
154
+
155
155
  # Class methods that will be attached to genereated remixed class
156
- #
156
+ #
157
157
  # These methods would be attached to the UserImage class given:
158
158
  # User.remixes n, :images
159
159
  #
160
160
  module RemixeeClassMethods
161
161
  end
162
-
162
+
163
163
  # Instances methods that will be attached to objects of the genereated remixed class
164
- #
164
+ #
165
165
  # These methods would be attached to UserImage objects given:
166
166
  # User.remixes n, :images
167
167
  #
168
168
  module RemixeeInstanceMethods
169
169
  end
170
- end
170
+ end
data/Rakefile CHANGED
@@ -1,51 +1,25 @@
1
- require 'rubygems'
2
- require 'spec'
3
- require 'spec/rake/spectask'
4
1
  require 'pathname'
2
+ require 'rubygems'
3
+
4
+ ROOT = Pathname(__FILE__).dirname.expand_path
5
+ JRUBY = RUBY_PLATFORM =~ /java/
6
+ WINDOWS = Gem.win_platform?
7
+ SUDO = (WINDOWS || JRUBY) ? '' : ('sudo' unless ENV['SUDOLESS'])
5
8
 
6
- ROOT = Pathname(__FILE__).dirname.expand_path
7
9
  require ROOT + 'lib/dm-is-remixable/is/version'
8
10
 
9
11
  AUTHOR = "Cory O'Daniel"
10
- EMAIL = "dm-is-remixable [a] coryodaniel [d] com"
11
- GEM_NAME = "dm-is-remixable"
12
+ EMAIL = 'dm-is-remixable [a] coryodaniel [d] com'
13
+ GEM_NAME = 'dm-is-remixable'
12
14
  GEM_VERSION = DataMapper::Is::Remixable::VERSION
13
15
  GEM_DEPENDENCIES = [['dm-core', "~>#{GEM_VERSION}"]]
14
- GEM_CLEAN = ["log", "pkg"]
15
- GEM_EXTRAS = { :has_rdoc => true, :extra_rdoc_files => %w[ README.txt LICENSE TODO ] }
16
-
17
- PROJECT_NAME = "datamapper"
18
- PROJECT_URL = "http://github.com/sam/dm-more/tree/master/dm-is-remixable"
19
- PROJECT_DESCRIPTION = PROJECT_SUMMARY = "dm-is-remixable allow you to create reusable data functionality"
20
-
21
- require ROOT.parent + 'tasks/hoe'
22
-
23
- task :default => [ :spec ]
24
-
25
- WIN32 = (RUBY_PLATFORM =~ /win32|mingw|cygwin/) rescue nil
26
- SUDO = WIN32 ? '' : ('sudo' unless ENV['SUDOLESS'])
27
-
28
- desc "Install #{GEM_NAME} #{GEM_VERSION}"
29
- task :install => [ :package ] do
30
- sh "#{SUDO} gem install --local pkg/#{GEM_NAME}-#{GEM_VERSION} --no-ri --no-rdoc --no-update-sources", :verbose => false
31
- end
32
-
33
- desc "Uninstall #{GEM_NAME} #{GEM_VERSION} (default ruby)"
34
- task :uninstall => [ :clobber ] do
35
- sh "#{SUDO} gem uninstall #{GEM_NAME} -v#{GEM_VERSION} -I -x", :verbose => false
36
- end
16
+ GEM_CLEAN = %w[ log pkg coverage ]
17
+ GEM_EXTRAS = { :has_rdoc => true, :extra_rdoc_files => %w[ README.txt LICENSE TODO History.txt ] }
37
18
 
38
- desc 'Run specifications'
39
- Spec::Rake::SpecTask.new(:spec) do |t|
40
- t.spec_opts << '--options' << 'spec/spec.opts' if File.exists?('spec/spec.opts')
41
- t.spec_files = Pathname.glob((ROOT + 'spec/**/*_spec.rb').to_s)
19
+ PROJECT_NAME = 'datamapper'
20
+ PROJECT_URL = "http://github.com/sam/dm-more/tree/master/#{GEM_NAME}"
21
+ PROJECT_DESCRIPTION = PROJECT_SUMMARY = 'dm-is-remixable allow you to create reusable data functionality'
42
22
 
43
- begin
44
- t.rcov = ENV.has_key?('NO_RCOV') ? ENV['NO_RCOV'] != 'true' : true
45
- t.rcov_opts << '--exclude' << 'spec'
46
- t.rcov_opts << '--text-summary'
47
- t.rcov_opts << '--sort' << 'coverage' << '--sort-reverse'
48
- rescue Exception
49
- # rcov not installed
50
- end
23
+ [ ROOT, ROOT.parent ].each do |dir|
24
+ Pathname.glob(dir.join('tasks/**/*.rb').to_s).each { |f| require f }
51
25
  end
data/TODO CHANGED
@@ -15,4 +15,4 @@ TODO
15
15
  - Test double+ remixing. User remixes Commentable; enhance Commentable remix Commentable
16
16
 
17
17
  - Remixable.related(*remixed_models)
18
- Taggable.related(Article, JobPostings)
18
+ Taggable.related(Article, JobPostings)
@@ -55,7 +55,7 @@ module DataMapper
55
55
  extend DataMapper::Is::Remixable::RemixeeClassMethods
56
56
  include DataMapper::Is::Remixable::RemixeeInstanceMethods
57
57
  @is_remixable = true
58
-
58
+
59
59
  # support clean suffixes for nested modules
60
60
  default_suffix = Extlib::Inflection.demodulize(self.name).singular.snake_case
61
61
  suffix(options.delete(:suffix) || default_suffix)
@@ -287,7 +287,7 @@ module DataMapper
287
287
  def remix_one_to_many(cardinality, model, options)
288
288
  self.has cardinality, (options[:as] || options[:table_name]).to_sym, :class_name => model.name
289
289
  model.property Extlib::Inflection.foreign_key(self.name).intern, Integer, :nullable => false
290
- model.belongs_to Extlib::Inflection.tableize(self.name).intern
290
+ model.belongs_to belongs_to_name(self.name)
291
291
  end
292
292
 
293
293
  # - remix_many_to_many
@@ -309,13 +309,13 @@ module DataMapper
309
309
  self.has cardinality, (options[:as] || options[:table_name]).to_sym, :class_name => model.name
310
310
  options[:other_model].has cardinality, options[:table_name].intern
311
311
 
312
- model.belongs_to Extlib::Inflection.tableize(self.name).intern
313
- model.belongs_to Extlib::Inflection.tableize(options[:other_model].name).intern
312
+ model.belongs_to belongs_to_name(self.name)
313
+ model.belongs_to belongs_to_name(options[:other_model].name)
314
314
  else
315
315
  raise Exception, "options[:via] must be specified when Remixing a module between two of the same class" unless options[:via]
316
316
 
317
317
  self.has cardinality, (options[:as] || options[:table_name]).to_sym, :class_name => model.name
318
- model.belongs_to Extlib::Inflection.tableize(self.name).intern
318
+ model.belongs_to belongs_to_name(self.name)
319
319
  model.belongs_to options[:via].intern, :class_name => options[:other_model].name, :child_key => ["#{options[:via]}_id".intern]
320
320
  end
321
321
  end
@@ -353,16 +353,20 @@ module DataMapper
353
353
  if Object.full_const_defined? "#{remixable}::RemixeeInstanceMethods"
354
354
  model.send :include, Object.full_const_get("#{remixable}::RemixeeInstanceMethods")
355
355
  end
356
-
356
+
357
357
  model
358
358
  end
359
359
 
360
+ def belongs_to_name(class_name)
361
+ class_name.to_const_path.gsub(/\//, '_').to_sym
362
+ end
363
+
360
364
  end # RemixerClassMethods
361
365
 
362
366
  # - RemixeeClassMethods
363
367
  # ==== Description
364
368
  # Methods available to any model that is :remixable
365
- module RemixeeClassMethods
369
+ module RemixeeClassMethods
366
370
  # - suffix
367
371
  # ==== Description
368
372
  # modifies the storage name suffix, which is by default based on the Remixable Module name
@@ -1,7 +1,7 @@
1
1
  module DataMapper
2
2
  module Is
3
3
  module Remixable
4
- VERSION = "0.9.8"
4
+ VERSION = '0.9.9'
5
5
  end
6
6
  end
7
7
  end
@@ -1,15 +1,11 @@
1
- # Needed to import datamapper and other gems
2
- require 'rubygems'
3
1
  require 'pathname'
2
+ require 'rubygems'
4
3
 
5
- # Add all external dependencies for the plugin here
6
- gem 'dm-core', '~>0.9.7'
4
+ gem 'dm-core', '~>0.9.9'
7
5
  require 'dm-core'
8
6
 
9
- # Require plugin-files
10
- require Pathname(__FILE__).dirname.expand_path / 'dm-is-remixable' / 'is' / 'remixable.rb'
7
+ require Pathname(__FILE__).dirname.expand_path / 'dm-is-remixable' / 'is' / 'remixable'
11
8
 
12
- # Include the plugin in Resource
13
9
  module DataMapper
14
10
  module Resource
15
11
  module ClassMethods
@@ -7,5 +7,5 @@ module Commentable
7
7
  property :id, Integer, :key => true, :serial => true
8
8
  property :comment, String
9
9
  property :created_at, DateTime
10
-
10
+
11
11
  end
data/spec/data/image.rb CHANGED
@@ -6,7 +6,7 @@ module Image
6
6
  property :id, Integer, :key => true, :serial => true
7
7
  property :description, String
8
8
  property :path, String
9
-
9
+
10
10
  # These methods will be available to the class remixing this module
11
11
  # If 'User' remixes 'Images', these methods will be available to a User class
12
12
  #
@@ -15,7 +15,7 @@ module Image
15
15
  'CLASS METHOD FOR REMIXER'
16
16
  end
17
17
  end
18
-
18
+
19
19
  # These methods will be available to instantiated objects of the remixing this module
20
20
  # If 'User' remixes 'Images', these methods will be available to a User object
21
21
  #
@@ -24,7 +24,7 @@ module Image
24
24
  'INSTANCE METHOD FOR REMIXER'
25
25
  end
26
26
  end
27
-
27
+
28
28
  # These methods will be available to the Generated Remixed Class
29
29
  # If 'User' remixes 'Images', these methods will be available to UserImage class
30
30
  #
@@ -33,7 +33,7 @@ module Image
33
33
  'CLASS METHOD FOR REMIXEE'
34
34
  end
35
35
  end
36
-
36
+
37
37
  # These methods will be available to an instantiated Generated Remixed Class
38
38
  # If 'User' remixes 'Images', these methods will be available to a UserImage object
39
39
  #
@@ -213,7 +213,7 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
213
213
  user2.comments.length.should be(0)
214
214
 
215
215
  comment.commentor.first_name.should == "Testy"
216
-
216
+
217
217
  user.comments.length.should be(1)
218
218
  end
219
219
 
@@ -240,7 +240,7 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
240
240
  article.comments.first.should be(ac)
241
241
  user.article_comments.first.should be(ac)
242
242
  end
243
-
243
+
244
244
  # Example:
245
245
  # Remixable Image add functionality to any class that remixes it
246
246
  # Image::RemixerClassMethods defines a method called 'total_images' that counts the total number of images for the class
@@ -249,17 +249,17 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
249
249
  # User.remixes n, :images
250
250
  # User.total_images => count of all images owned by all users
251
251
  # User.first.most_viewed_image => would return the most viewed image
252
- #
252
+ #
253
253
  it "should add a remixables' 'RemixerClassMethods' modules to the remixing class" do
254
254
  Article.respond_to?(:test_remixer_class_method).should be(true)
255
255
  Article.test_remixer_class_method.should == 'CLASS METHOD FOR REMIXER'
256
256
  end
257
-
257
+
258
258
  it "should add a remixables' 'RemixerInstanceMethods' modules to the remixing class" do
259
259
  Article.new.respond_to?(:test_remixer_instance_method).should be(true)
260
260
  Article.new.test_remixer_instance_method.should == 'INSTANCE METHOD FOR REMIXER'
261
261
  end
262
-
262
+
263
263
  # Example:
264
264
  # Remixable Image add functionality to any class that remixes it
265
265
  # Image::RemixeeClassMethods defines a method called 'damaged_files' would return a list of all images with invalid checksums (or whatev)
@@ -274,49 +274,49 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
274
274
  ArticleImage.respond_to?(:test_remixee_class_method).should be(true)
275
275
  ArticleImage.test_remixee_class_method.should == 'CLASS METHOD FOR REMIXEE'
276
276
  end
277
-
277
+
278
278
  it "should add a remixables' 'RemixeeInstanceMethods' modules to the generated remixed class" do
279
279
  ArticleImage.new.respond_to?(:test_remixee_instance_method).should be(true)
280
280
  ArticleImage.new.test_remixee_instance_method.should == 'INSTANCE METHOD FOR REMIXEE'
281
281
  end
282
-
282
+
283
283
  # Example:
284
284
  # User.remixes n, :images, :as => "pics"
285
285
  # User.first.pics would be the acessor for images
286
286
  # User.first.user_images should raise method not found
287
287
  #
288
288
  it 'should remove the original attribute accessor when attaching an optional one' do
289
- Article.new.respond_to?(:pics).should be(true)
289
+ Article.new.respond_to?(:pics).should be(true)
290
290
  User.new.respond_to?(:user_addresses).should be(true)
291
291
  end
292
-
292
+
293
293
  # Currently:
294
294
  # Submission.remixes n, :comments
295
295
  # SubmissionComment.new.user = User.first => throws exception, accessor name is 'users' instead
296
296
  #
297
297
  # Example:
298
- # User.remix 1, :images
298
+ # User.remix 1, :images
299
299
  # # => User.image & UserImage.user
300
300
  #
301
- # User.remix n, :images
301
+ # User.remix n, :images
302
302
  # # => User.images & UserImage.user
303
- #
303
+ #
304
304
  # User.remix n, :comments, :for => 'User', :via => 'commentor'
305
305
  # # => User.comments & UserComment.user & UserComment.commentor
306
306
  #
307
307
  it 'should pluralize accessor names with respect to cardinality' do
308
308
  pending
309
309
  end
310
-
310
+
311
311
  # Note:
312
312
  # Currently the :via flag allows one to specify another name for the field, but it always appends _id
313
- #
313
+ #
314
314
  # Example:
315
315
  # User w/ PK being 'login_name'
316
316
  # User.remixes n, :comments, :for => 'User', :via => 'commentor'
317
- #
317
+ #
318
318
  # Comment Table:
319
- # * id
319
+ # * id
320
320
  # * text
321
321
  # * user_login_name
322
322
  # * commentor_id #=> should be able to specify it to be commentor_login_name
data/spec/spec.opts CHANGED
@@ -1,2 +1 @@
1
- --format specdoc
2
1
  --colour
data/spec/spec_helper.rb CHANGED
@@ -1,22 +1,26 @@
1
+ require 'pathname'
1
2
  require 'rubygems'
2
- gem 'rspec', '>=1.1.3'
3
+
4
+ gem 'rspec', '~>1.1.11'
3
5
  require 'spec'
4
- require 'pathname'
5
- require Pathname(__FILE__).dirname.expand_path.parent + 'lib/dm-is-remixable'
6
+
7
+ ROOT = Pathname(__FILE__).dirname.parent.expand_path
8
+
9
+ # use local dm-types if running from dm-more directly
10
+ lib = ROOT.parent.join('dm-types', 'lib').expand_path
11
+ $LOAD_PATH.unshift(lib) if lib.directory?
12
+
13
+ require ROOT + 'lib/dm-is-remixable'
6
14
 
7
15
  def load_driver(name, default_uri)
8
16
  return false if ENV['ADAPTER'] != name.to_s
9
17
 
10
- lib = "do_#{name}"
11
-
12
18
  begin
13
- gem lib, '~>0.9.7'
14
- require lib
15
19
  DataMapper.setup(name, ENV["#{name.to_s.upcase}_SPEC_URI"] || default_uri)
16
20
  DataMapper::Repository.adapters[:default] = DataMapper::Repository.adapters[name]
17
21
  true
18
- rescue Gem::LoadError => e
19
- warn "Could not load #{lib}: #{e}"
22
+ rescue LoadError => e
23
+ warn "Could not load do_#{name}: #{e}"
20
24
  false
21
25
  end
22
26
  end
data/tasks/install.rb ADDED
@@ -0,0 +1,13 @@
1
+ def sudo_gem(cmd)
2
+ sh "#{SUDO} #{RUBY} -S gem #{cmd}", :verbose => false
3
+ end
4
+
5
+ desc "Install #{GEM_NAME} #{GEM_VERSION}"
6
+ task :install => [ :package ] do
7
+ sudo_gem "install --local pkg/#{GEM_NAME}-#{GEM_VERSION} --no-update-sources"
8
+ end
9
+
10
+ desc "Uninstall #{GEM_NAME} #{GEM_VERSION}"
11
+ task :uninstall => [ :clobber ] do
12
+ sudo_gem "uninstall #{GEM_NAME} -v#{GEM_VERSION} -Ix"
13
+ end
data/tasks/spec.rb ADDED
@@ -0,0 +1,25 @@
1
+ begin
2
+ gem 'rspec', '~>1.1.11'
3
+ require 'spec'
4
+ require 'spec/rake/spectask'
5
+
6
+ task :default => [ :spec ]
7
+
8
+ desc 'Run specifications'
9
+ Spec::Rake::SpecTask.new(:spec) do |t|
10
+ t.spec_opts << '--options' << 'spec/spec.opts' if File.exists?('spec/spec.opts')
11
+ t.spec_files = Pathname.glob((ROOT + 'spec/**/*_spec.rb').to_s)
12
+
13
+ begin
14
+ gem 'rcov', '~>0.8'
15
+ t.rcov = JRUBY ? false : (ENV.has_key?('NO_RCOV') ? ENV['NO_RCOV'] != 'true' : true)
16
+ t.rcov_opts << '--exclude' << 'spec'
17
+ t.rcov_opts << '--text-summary'
18
+ t.rcov_opts << '--sort' << 'coverage' << '--sort-reverse'
19
+ rescue LoadError
20
+ # rcov not installed
21
+ end
22
+ end
23
+ rescue LoadError
24
+ # rspec not installed
25
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dm-is-remixable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.8
4
+ version: 0.9.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cory O'Daniel
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-09 00:00:00 -08:00
12
+ date: 2009-01-04 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ~>
22
22
  - !ruby/object:Gem::Version
23
- version: 0.9.8
23
+ version: 0.9.9
24
24
  version:
25
25
  description: dm-is-remixable allow you to create reusable data functionality
26
26
  email:
@@ -33,6 +33,7 @@ extra_rdoc_files:
33
33
  - README.txt
34
34
  - LICENSE
35
35
  - TODO
36
+ - History.txt
36
37
  files:
37
38
  - History.txt
38
39
  - LICENSE
@@ -58,6 +59,8 @@ files:
58
59
  - spec/integration/remixable_spec.rb
59
60
  - spec/spec.opts
60
61
  - spec/spec_helper.rb
62
+ - tasks/install.rb
63
+ - tasks/spec.rb
61
64
  has_rdoc: true
62
65
  homepage: http://github.com/sam/dm-more/tree/master/dm-is-remixable
63
66
  post_install_message: