tableless_model 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,34 +1,21 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vitobotta/tableless_model (0.0.1)
4
+ tableless_model (0.0.4)
5
5
  validatable
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
- activemodel (3.0.3)
11
- activesupport (= 3.0.3)
12
- builder (~> 2.1.2)
13
- i18n (~> 0.4)
14
- activerecord (3.0.3)
15
- activemodel (= 3.0.3)
16
- activesupport (= 3.0.3)
17
- arel (~> 2.0.2)
18
- tzinfo (~> 0.3.23)
19
- activesupport (3.0.3)
20
- arel (2.0.6)
21
- builder (2.1.2)
22
- i18n (0.5.0)
10
+ ansi (1.2.2)
23
11
  minitest (2.0.2)
24
- tzinfo (0.3.23)
25
12
  validatable (1.6.7)
26
13
 
27
14
  PLATFORMS
28
15
  ruby
29
16
 
30
17
  DEPENDENCIES
31
- activerecord
18
+ ansi
32
19
  minitest
20
+ tableless_model!
33
21
  validatable
34
- vitobotta/tableless_model!
data/README.rdoc CHANGED
@@ -7,6 +7,7 @@ Tableless Model behaves in a similar way to normal ActiveRecord models in that i
7
7
 
8
8
  In particular, by using Tableless Model, you could save tables whenever you have one to one associations between a parent model and a child model containing options, settings, debugging information or any other collection of attributes that belongs uniquely to a single parent object.
9
9
 
10
+ Removing database tables also means reducing the number of queries to fetch associations, therefore it can also help a little bit with performance.
10
11
 
11
12
 
12
13
  == Installation
@@ -15,7 +16,7 @@ Tableless Model is available as a Rubygem:
15
16
 
16
17
  gem install tableless_model
17
18
 
18
- (current version: 0.0.3)
19
+ (current version: 0.0.4)
19
20
 
20
21
 
21
22
  == Usage
@@ -28,7 +29,7 @@ For example's sake, say we have these two models:
28
29
 
29
30
  # having columns such as id, title, etc
30
31
 
31
- has_one :seo_settings
32
+ has_one :seo_options
32
33
 
33
34
  end
34
35
 
@@ -48,7 +49,7 @@ For example's sake, say we have these two models:
48
49
 
49
50
  So that each instance of Page has its own SEO options, and these options/settings only belong to a page, so we have a one to one association, and our database will have the tables "pages", and "seo_options".
50
51
 
51
- Using Tableless Model, we could remove the association and the table seo_options altogether, by storing those options in a column in the pages table, in a YAML::serialized form. So the models become:
52
+ Using Tableless Model, we could remove the association and the table seo_options altogether, by storing those options in a column of the pages table, in a YAML-serialized form. So the models become:
52
53
 
53
54
 
54
55
  1)
@@ -122,7 +123,7 @@ And this is how the content of the serialized column would look like in the data
122
123
 
123
124
  == Validations
124
125
 
125
- Tableless Model uses the gem Validatable to support validations methods and callbacks (such as "after_validation").
126
+ Tableless Model uses the Validatable gem to support validations methods and callbacks (such as "after_validation").
126
127
  Note: it currently uses the Rails 2.x syntax only.
127
128
 
128
129
  Example:
@@ -46,7 +46,7 @@ module Base
46
46
  # model and not just a normal hash or the value of the attribute in the database,
47
47
  # which is plain text
48
48
  define_method column_name.to_s do
49
- class_type.new(read_attribute(class_name.to_sym) || {})
49
+ class_type.new(read_attribute(column_name.to_sym) || {})
50
50
  end
51
51
 
52
52
  # Adding setter for the serialized column,
@@ -58,7 +58,8 @@ module Base
58
58
  end
59
59
  end
60
60
 
61
-
61
+
62
+
62
63
  #
63
64
  #
64
65
  # Overriding the setter for the serialized column in the AR model,
@@ -68,20 +69,20 @@ module Base
68
69
  #
69
70
  def default_value_for(property, default_value)
70
71
  unless method_defined? "after_initialize_with_default_value_for_#{property.to_s}"
71
-
72
+
72
73
  unless method_defined? "after_initialize"
73
74
  define_method "after_initialize" do |*args|
74
75
  end
75
76
  end
76
-
77
+
77
78
  define_method "after_initialize_with_default_value_for_#{property.to_s}" do |*args|
78
79
  send("after_initialize_without_default_value_for_#{property.to_s}", *args)
79
80
  return unless new_record?
80
81
  return unless self.respond_to?(property.to_sym)
81
-
82
+
82
83
  self.send("#{property.to_s}=".to_sym, self.send(property.to_sym) || default_value)
83
84
  end
84
-
85
+
85
86
  alias_method_chain "after_initialize", "default_value_for_#{property.to_s}"
86
87
  end
87
88
  end
@@ -1,3 +1,3 @@
1
1
  module TablelessModel
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -1,11 +1,12 @@
1
- require File.join(File.dirname(__FILE__), "test_helper")
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "test_helper"))
2
2
 
3
3
  require "active_record"
4
- require "lib/tableless_model"
5
4
  require 'minitest/autorun'
6
5
 
6
+ require File.expand_path(File.join(File.dirname(__FILE__), "../lib/tableless_model"))
7
7
 
8
- describe "A class inheriting from ActiveRecord::TablelessModel " do
8
+
9
+ describe "A class inheriting from ActiveRecord::TablelessModel" do
9
10
  before do
10
11
  class TestClass1 < ActiveRecord::TablelessModel
11
12
  end
@@ -119,7 +120,7 @@ describe "An instance of TablelessModel" do
119
120
  # excluding some test values that would always fail depending on the type
120
121
  exclude_test_values = case type
121
122
  when :decimal then [ "test", true ]
122
- when :time then [ 1234, true ]
123
+ when :time then [ "test", 1234, true ]
123
124
  when :date then [ "test", 1234, true, "1234.12" ]
124
125
  when :datetime then [ "test", 1234, true ]
125
126
  else []
data/spec/test_helper.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'rubygems'
2
- require 'minitest/unit'
3
- require 'minitest/spec'
2
+ gem "minitest"
3
+ require 'minitest/autorun'
4
+
4
5
  require 'ansi'
5
6
 
6
7
  class MiniTest::Unit
@@ -43,13 +44,14 @@ class MiniTest::Unit
43
44
  def run_test_suites(filter = /./)
44
45
  @test_count, @assertion_count = 0, 0
45
46
  old_sync, @@out.sync = @@out.sync, true if @@out.respond_to? :sync=
47
+
46
48
  TestCase.test_suites.each do |suite|
47
49
  test_cases = suite.test_methods.grep(filter)
48
50
  if test_cases.size > 0
49
51
  @@out.print "\n#{suite}:\n"
50
52
  end
51
53
 
52
- test_cases.each do |test|
54
+ test_cases.each do |test|
53
55
  inst = suite.new test
54
56
  inst._assertions = 0
55
57
 
@@ -77,7 +79,7 @@ class MiniTest::Unit
77
79
  @@out.print " (%.2fs) " % (Time.now - t)
78
80
 
79
81
  if @broken
80
- @@out.puts
82
+ @@out.puts
81
83
 
82
84
  report = @report.last
83
85
  @@out.puts pad(report[:message], 10)
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tableless_model
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease:
4
+ prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 0
9
- - 3
10
- version: 0.0.3
8
+ - 4
9
+ version: 0.0.4
11
10
  platform: ruby
12
11
  authors:
13
12
  - Vito Botta
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2011-01-03 00:00:00 +00:00
17
+ date: 2011-01-11 00:00:00 +00:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -26,7 +25,6 @@ dependencies:
26
25
  requirements:
27
26
  - - ">="
28
27
  - !ruby/object:Gem::Version
29
- hash: 3
30
28
  segments:
31
29
  - 0
32
30
  version: "0"
@@ -40,7 +38,6 @@ dependencies:
40
38
  requirements:
41
39
  - - ">="
42
40
  - !ruby/object:Gem::Version
43
- hash: 3
44
41
  segments:
45
42
  - 0
46
43
  version: "0"
@@ -54,7 +51,6 @@ dependencies:
54
51
  requirements:
55
52
  - - ">="
56
53
  - !ruby/object:Gem::Version
57
- hash: 3
58
54
  segments:
59
55
  - 0
60
56
  version: "0"
@@ -97,7 +93,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
97
93
  requirements:
98
94
  - - ">="
99
95
  - !ruby/object:Gem::Version
100
- hash: 3
101
96
  segments:
102
97
  - 0
103
98
  version: "0"
@@ -106,14 +101,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
101
  requirements:
107
102
  - - ">="
108
103
  - !ruby/object:Gem::Version
109
- hash: 3
110
104
  segments:
111
105
  - 0
112
106
  version: "0"
113
107
  requirements: []
114
108
 
115
109
  rubyforge_project: tableless_model
116
- rubygems_version: 1.4.1
110
+ rubygems_version: 1.3.7
117
111
  signing_key:
118
112
  specification_version: 3
119
113
  summary: A serialisable and validatable table-less model with support for associations, useful to store settings, options, etc in a serialized form in a parent object