rughetto-ar_object_pack 0.0.2 → 0.0.4

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/Rakefile CHANGED
@@ -9,7 +9,7 @@ require 'merb-core'
9
9
  require 'merb-core/tasks/merb'
10
10
 
11
11
  GEM_NAME = "ar_object_pack"
12
- GEM_VERSION = "0.0.2"
12
+ GEM_VERSION = "0.0.4"
13
13
  AUTHOR = "Rue The Ghetto"
14
14
  EMAIL = "ru_ghetto@rubyghetto.com"
15
15
  HOMEPAGE = "http://github.com/rughetto/ar_object_pack"
data/TODO CHANGED
@@ -1,5 +1,5 @@
1
1
  TODO:
2
2
 
3
- Create instructions for installation with Rails
4
-
5
- Think about validations, etc for packaging enumerable values and other useful objects from Datamapper
3
+ * Get SetTyping related stuff working -
4
+ * is_in_set class method will validate that the string is in an allowable set of values
5
+ * is_a_subset packages an array into the database, and validates that the values are acceptable
@@ -1,18 +1,17 @@
1
- # make sure we're running inside Merb
2
1
  if defined?(Merb::Plugins)
3
-
4
- # Merb gives you a Merb::Plugins.config hash...feel free to put your stuff in your piece of it
5
- Merb::Plugins.config[:ar_object_pack] = {}
2
+ Merb::Plugins.config[:ar_object_pack] = {} # nothing yet needed
6
3
 
7
4
  Merb::BootLoader.before_app_loads do
8
5
  # load ObjectPacker into AR Base
9
6
  require File.dirname(__FILE__) + '/ar_object_pack/object_packer'
10
7
  ActiveRecord::Base.send(:extend, ArObjectPack::ObjectPackager::ActiveRecordMethods)
8
+
9
+ # load ObjectPacker into AR Base
10
+ # require File.dirname(__FILE__) + '/ar_object_pack/set_typer'
11
+ # ActiveRecord::Base.send(:extend, ArObjectPack::SetTyper::ActiveRecordMethods)
11
12
  end
12
13
 
13
14
  Merb::BootLoader.after_app_loads do
14
- # code that can be required after the application loads
15
+ # nothing yet needed
15
16
  end
16
-
17
- # Merb::Plugins.add_rakefiles "ar_object_pack/merbtasks"
18
17
  end
@@ -11,7 +11,7 @@ module ArObjectPack
11
11
  # arguments: meth
12
12
  module ActiveRecordMethods
13
13
  def package( meth, pack_type=:marshal )
14
- raise ArgumentError, "#{meth} is not a database attribute " unless self.new.attributes.keys.include?( meth.to_s )
14
+ raise ArgumentError, "#{meth} is not a database attribute. Perhaps you need to migrate." unless self.columns.collect(&:name).include?( meth.to_s )
15
15
  include ArObjectPack::ObjectPackager::InstanceMethods unless self.respond_to?(:do_pack)
16
16
 
17
17
  pack_type = :marshal unless pack_formats.include?( pack_type )
@@ -6,14 +6,15 @@ require 'rubygems'
6
6
  require 'active_record'
7
7
  require 'sqlite3'
8
8
 
9
- # files for testing
10
- require File.dirname(__FILE__) + '/../lib/ar_object_pack/object_packer'
11
-
12
9
  # establish database and test classes
13
10
  require File.dirname(__FILE__) + "/database_spec_setup"
14
11
  include DatabaseSpecSetup
15
12
 
16
13
  describe "ar_object_pack" do
14
+ after(:all) do
15
+ File.delete("object_pack_tester.db") if File.file?("object_pack_tester.db")
16
+ end
17
+
17
18
  describe "testing setup: " do
18
19
  it "have all the needed gems and files to run" do
19
20
  # before block should not throw error and the following should pass!
@@ -184,5 +185,28 @@ describe "ar_object_pack" do
184
185
  }.should raise_error
185
186
  end
186
187
  end
187
- end
188
+ end
189
+
190
+ describe 'set typing' do
191
+ describe 'is_in_set' do
192
+ before(:each) do
193
+ @roles_array = [1,2,3,4]
194
+ end
195
+
196
+ it "should create a class inheritable array to hold the set value" do
197
+ Setter.respond_to?(:role_set)
198
+ end
199
+
200
+ it "should set the class inheritable array to the set" do
201
+ pending
202
+ Setter.role_set.should == @roles_array
203
+ end
204
+
205
+ it "should throw an argument error if the set is not an array"
206
+ it "should throw an argument error if the set array is empty"
207
+ it "record should be valid if the is_in_set attribute is blank"
208
+ it "record should be valid if the attribute is a member of the set"
209
+ it "record should not be valid the value is not in the set"
210
+ end
211
+ end
188
212
  end
@@ -2,9 +2,14 @@ module DatabaseSpecSetup
2
2
  # remove the old database
3
3
  File.delete("object_pack_tester.db") if File.file?("object_pack_tester.db")
4
4
 
5
+ # grab the files
6
+ require File.dirname(__FILE__) + '/../lib/ar_object_pack/object_packer'
7
+ require File.dirname(__FILE__) + '/../lib/ar_object_pack/set_typing'
8
+
5
9
  # send methods to base
6
10
  ActiveRecord::Base.send(:extend, ArObjectPack::ObjectPackager::ActiveRecordMethods)
7
-
11
+ ActiveRecord::Base.send(:extend, ArObjectPack::SetTyping::ActiveRecordMethods)
12
+
8
13
  # establish a connection to the sqlite database
9
14
  ActiveRecord::Base.establish_connection(
10
15
  :adapter => 'sqlite3',
@@ -22,6 +27,12 @@ module DatabaseSpecSetup
22
27
  t.column :obj_marshal_64, :text
23
28
  end
24
29
 
30
+ # table for testing different set configurations
31
+ create_table :setters, :force => true do |t|
32
+ t.column :role, :str
33
+ t.column :teams, :str
34
+ end
35
+
25
36
  # table for testing basic database writes and reads to ensure correct setup
26
37
  create_table :testings, :force => true do |t|
27
38
  t.column :str, :string
@@ -35,7 +46,12 @@ module DatabaseSpecSetup
35
46
  package :obj_yaml, :yaml
36
47
  package :obj_json, :json
37
48
  package :obj_marshal_64, :marshal_64
38
- end
49
+ end
50
+
51
+ class Setter < ActiveRecord::Base
52
+ is_in_set :role, [1,2,3,4]
53
+ #is_a_subset :teams, ['programmers', 'system administrators', 'rubyists', 'web developers']
54
+ end
39
55
 
40
56
  class Testing < ActiveRecord::Base; end
41
57
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rughetto-ar_object_pack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rue The Ghetto
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-05 00:00:00 -08:00
12
+ date: 2009-01-21 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -47,6 +47,7 @@ files:
47
47
  - TODO
48
48
  - lib/ar_object_pack
49
49
  - lib/ar_object_pack/object_packer.rb
50
+ - lib/ar_object_pack/set_typing.rb
50
51
  - lib/ar_object_pack.rb
51
52
  - spec/ar_object_pack_spec.rb
52
53
  - spec/database_spec_setup.rb