has_metadata 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +7 -10
- data/Gemfile.lock +52 -56
- data/LICENSE +1 -1
- data/README.textile +23 -2
- data/Rakefile +11 -9
- data/VERSION +1 -1
- data/has_metadata.gemspec +37 -23
- data/lib/{metadata_generator.rb → has_metadata/metadata_generator.rb} +1 -1
- data/lib/has_metadata/model.rb +40 -0
- data/lib/has_metadata.rb +25 -14
- data/spec/has_metadata_spec.rb +11 -1
- data/spec/spec_helper.rb +0 -1
- data/templates/create_metadata.rb +1 -1
- data/templates/metadata.rb +1 -32
- metadata +72 -7
- data/.gitignore +0 -26
data/Gemfile
CHANGED
@@ -1,14 +1,11 @@
|
|
1
1
|
source :rubygems
|
2
2
|
|
3
|
-
# DEPENDENCIES
|
4
3
|
gem 'rails', '>= 3.0'
|
5
4
|
|
6
|
-
|
7
|
-
gem 'jeweler'
|
8
|
-
gem 'yard'
|
9
|
-
gem 'RedCloth', require: 'redcloth'
|
10
|
-
gem 'sqlite3'
|
11
|
-
|
12
|
-
|
13
|
-
gem 'rspec'
|
14
|
-
|
5
|
+
group :development do
|
6
|
+
gem 'jeweler'
|
7
|
+
gem 'yard'
|
8
|
+
gem 'RedCloth', require: 'redcloth'
|
9
|
+
gem 'sqlite3'
|
10
|
+
gem 'rspec'
|
11
|
+
end
|
data/Gemfile.lock
CHANGED
@@ -3,49 +3,46 @@ GEM
|
|
3
3
|
specs:
|
4
4
|
RedCloth (4.2.3)
|
5
5
|
abstract (1.0.0)
|
6
|
-
actionmailer (3.0.
|
7
|
-
actionpack (= 3.0.
|
8
|
-
mail (~> 2.2.
|
9
|
-
actionpack (3.0.
|
10
|
-
activemodel (= 3.0.
|
11
|
-
activesupport (= 3.0.
|
6
|
+
actionmailer (3.0.3)
|
7
|
+
actionpack (= 3.0.3)
|
8
|
+
mail (~> 2.2.9)
|
9
|
+
actionpack (3.0.3)
|
10
|
+
activemodel (= 3.0.3)
|
11
|
+
activesupport (= 3.0.3)
|
12
12
|
builder (~> 2.1.2)
|
13
13
|
erubis (~> 2.6.6)
|
14
|
-
i18n (~> 0.4
|
14
|
+
i18n (~> 0.4)
|
15
15
|
rack (~> 1.2.1)
|
16
|
-
rack-mount (~> 0.6.
|
17
|
-
rack-test (~> 0.5.
|
16
|
+
rack-mount (~> 0.6.13)
|
17
|
+
rack-test (~> 0.5.6)
|
18
18
|
tzinfo (~> 0.3.23)
|
19
|
-
activemodel (3.0.
|
20
|
-
activesupport (= 3.0.
|
19
|
+
activemodel (3.0.3)
|
20
|
+
activesupport (= 3.0.3)
|
21
21
|
builder (~> 2.1.2)
|
22
|
-
i18n (~> 0.4
|
23
|
-
activerecord (3.0.
|
24
|
-
activemodel (= 3.0.
|
25
|
-
activesupport (= 3.0.
|
26
|
-
arel (~>
|
22
|
+
i18n (~> 0.4)
|
23
|
+
activerecord (3.0.3)
|
24
|
+
activemodel (= 3.0.3)
|
25
|
+
activesupport (= 3.0.3)
|
26
|
+
arel (~> 2.0.2)
|
27
27
|
tzinfo (~> 0.3.23)
|
28
|
-
activeresource (3.0.
|
29
|
-
activemodel (= 3.0.
|
30
|
-
activesupport (= 3.0.
|
31
|
-
activesupport (3.0.
|
32
|
-
arel (
|
33
|
-
activesupport (~> 3.0.0)
|
28
|
+
activeresource (3.0.3)
|
29
|
+
activemodel (= 3.0.3)
|
30
|
+
activesupport (= 3.0.3)
|
31
|
+
activesupport (3.0.3)
|
32
|
+
arel (2.0.3)
|
34
33
|
builder (2.1.2)
|
35
34
|
diff-lcs (1.1.2)
|
36
35
|
erubis (2.6.6)
|
37
36
|
abstract (>= 1.0.0)
|
38
37
|
ffi (0.6.3)
|
39
38
|
rake (>= 0.8.7)
|
40
|
-
gemcutter (0.6.1)
|
41
39
|
git (1.2.5)
|
42
40
|
i18n (0.4.2)
|
43
|
-
jeweler (1.
|
44
|
-
|
41
|
+
jeweler (1.5.1)
|
42
|
+
bundler (~> 1.0.0)
|
45
43
|
git (>= 1.2.5)
|
46
|
-
|
47
|
-
|
48
|
-
mail (2.2.9)
|
44
|
+
rake
|
45
|
+
mail (2.2.10)
|
49
46
|
activesupport (>= 2.3.6)
|
50
47
|
i18n (~> 0.4.1)
|
51
48
|
mime-types (~> 1.16)
|
@@ -57,39 +54,35 @@ GEM
|
|
57
54
|
rack (>= 1.0.0)
|
58
55
|
rack-test (0.5.6)
|
59
56
|
rack (>= 1.0)
|
60
|
-
rails (3.0.
|
61
|
-
actionmailer (= 3.0.
|
62
|
-
actionpack (= 3.0.
|
63
|
-
activerecord (= 3.0.
|
64
|
-
activeresource (= 3.0.
|
65
|
-
activesupport (= 3.0.
|
66
|
-
bundler (~> 1.0
|
67
|
-
railties (= 3.0.
|
68
|
-
railties (3.0.
|
69
|
-
actionpack (= 3.0.
|
70
|
-
activesupport (= 3.0.
|
71
|
-
rake (>= 0.8.
|
72
|
-
thor (~> 0.14.
|
57
|
+
rails (3.0.3)
|
58
|
+
actionmailer (= 3.0.3)
|
59
|
+
actionpack (= 3.0.3)
|
60
|
+
activerecord (= 3.0.3)
|
61
|
+
activeresource (= 3.0.3)
|
62
|
+
activesupport (= 3.0.3)
|
63
|
+
bundler (~> 1.0)
|
64
|
+
railties (= 3.0.3)
|
65
|
+
railties (3.0.3)
|
66
|
+
actionpack (= 3.0.3)
|
67
|
+
activesupport (= 3.0.3)
|
68
|
+
rake (>= 0.8.7)
|
69
|
+
thor (~> 0.14.4)
|
73
70
|
rake (0.8.7)
|
74
|
-
rspec (2.0
|
75
|
-
rspec-core (~> 2.0
|
76
|
-
rspec-expectations (~> 2.0
|
77
|
-
rspec-mocks (~> 2.0
|
78
|
-
rspec-core (2.0
|
79
|
-
rspec-expectations (2.0
|
80
|
-
diff-lcs (
|
81
|
-
rspec-mocks (2.0
|
82
|
-
rspec-core (~> 2.0.1)
|
83
|
-
rspec-expectations (~> 2.0.1)
|
84
|
-
rubyforge (2.0.4)
|
85
|
-
json_pure (>= 1.1.7)
|
71
|
+
rspec (2.1.0)
|
72
|
+
rspec-core (~> 2.1.0)
|
73
|
+
rspec-expectations (~> 2.1.0)
|
74
|
+
rspec-mocks (~> 2.1.0)
|
75
|
+
rspec-core (2.1.0)
|
76
|
+
rspec-expectations (2.1.0)
|
77
|
+
diff-lcs (~> 1.1.2)
|
78
|
+
rspec-mocks (2.1.0)
|
86
79
|
sqlite3 (0.1.1)
|
87
80
|
ffi (>= 0.6.3)
|
88
|
-
thor (0.14.
|
89
|
-
treetop (1.4.
|
81
|
+
thor (0.14.4)
|
82
|
+
treetop (1.4.9)
|
90
83
|
polyglot (>= 0.3.1)
|
91
84
|
tzinfo (0.3.23)
|
92
|
-
yard (0.6.
|
85
|
+
yard (0.6.2)
|
93
86
|
|
94
87
|
PLATFORMS
|
95
88
|
ruby
|
@@ -101,3 +94,6 @@ DEPENDENCIES
|
|
101
94
|
rspec
|
102
95
|
sqlite3
|
103
96
|
yard
|
97
|
+
|
98
|
+
METADATA
|
99
|
+
version: 1.0.6
|
data/LICENSE
CHANGED
data/README.textile
CHANGED
@@ -1,9 +1,30 @@
|
|
1
1
|
h1. has_metadata -- Keep your tables narrow
|
2
2
|
|
3
3
|
| *Author* | Tim Morgan |
|
4
|
-
| *Version* | 1.
|
4
|
+
| *Version* | 1.1 (Nov 16, 2010) |
|
5
5
|
| *License* | Released under the MIT License. |
|
6
6
|
|
7
|
+
h2. Important note for those upgrading from 1.0 to 1.1
|
8
|
+
|
9
|
+
You must re-run the @rails generate metadata@ task to update your @Metadata@
|
10
|
+
model. When finished, your @app/models/metadata.rb@ file should look like:
|
11
|
+
|
12
|
+
<pre><code>
|
13
|
+
# Stores information about a model that doesn't need to be in that model's
|
14
|
+
# table. Each row in the @metadata@ table stores a schemaless, serialized hash
|
15
|
+
# of data associated with a model instance. Any model can have an associated row
|
16
|
+
# in the @metadata@ table by using the {HasMetadata} module.
|
17
|
+
#
|
18
|
+
# h2. Properties
|
19
|
+
#
|
20
|
+
# | @data@ | A hash of this metadata's contents (YAML serialized in the database). |
|
21
|
+
|
22
|
+
class Metadata < HasMetadata::Model
|
23
|
+
end
|
24
|
+
</code></pre>
|
25
|
+
|
26
|
+
Note that this is significantly emptier than the previous model.
|
27
|
+
|
7
28
|
h2. About
|
8
29
|
|
9
30
|
Wide tables are a problem for big databases. If your @ActiveRecord@ models have
|
@@ -66,7 +87,7 @@ t.belongs_to :metadata
|
|
66
87
|
|
67
88
|
Next, include the @HasMetadata@ module in your model, and call the
|
68
89
|
@has_metadata@ method to define the schema of your metadata. You can get more
|
69
|
-
information in the
|
90
|
+
information in the {HasMetadata::ClassMethods#has_metadata} documentation, but for starters, here's a
|
70
91
|
basic example:
|
71
92
|
|
72
93
|
<pre><code>
|
data/Rakefile
CHANGED
@@ -1,13 +1,15 @@
|
|
1
|
-
require '
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
2
3
|
begin
|
3
|
-
|
4
|
-
rescue
|
5
|
-
puts
|
6
|
-
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
7
9
|
end
|
10
|
+
require 'rake'
|
8
11
|
|
9
|
-
|
10
|
-
|
12
|
+
require 'jeweler'
|
11
13
|
Jeweler::Tasks.new do |gem|
|
12
14
|
gem.name = "has_metadata"
|
13
15
|
gem.summary = %Q{Reduce your table width by moving non-indexed columns to a separate metadata table}
|
@@ -16,13 +18,13 @@ Jeweler::Tasks.new do |gem|
|
|
16
18
|
gem.homepage = "http://github.com/riscfuture/has_metadata"
|
17
19
|
gem.authors = [ "Tim Morgan" ]
|
18
20
|
gem.required_ruby_version = '>= 1.9'
|
19
|
-
gem.add_dependency "rails", ">= 3.0"
|
20
21
|
end
|
21
|
-
Jeweler::
|
22
|
+
Jeweler::RubygemsDotOrgTasks.new
|
22
23
|
|
23
24
|
require 'rspec/core/rake_task'
|
24
25
|
RSpec::Core::RakeTask.new
|
25
26
|
|
27
|
+
require 'yard'
|
26
28
|
YARD::Rake::YardocTask.new('doc') do |doc|
|
27
29
|
doc.options << "-m" << "textile"
|
28
30
|
doc.options << "--protected"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.1.0
|
data/has_metadata.gemspec
CHANGED
@@ -1,50 +1,49 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{has_metadata}
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Tim Morgan"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-11-17}
|
13
13
|
s.description = %q{has_metadata lets you move non-indexed and weighty columns off of your big tables by creating a separate metadata table to store all this extra information. Works with Ruby 1.9. and Rails 3.0.}
|
14
14
|
s.email = %q{git@timothymorgan.info}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
|
-
|
17
|
+
"README.textile"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE",
|
25
|
+
"README.textile",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"has_metadata.gemspec",
|
29
|
+
"lib/has_metadata.rb",
|
30
|
+
"lib/has_metadata/metadata_generator.rb",
|
31
|
+
"lib/has_metadata/model.rb",
|
32
|
+
"spec/has_metadata_spec.rb",
|
33
|
+
"spec/metadata_spec.rb",
|
34
|
+
"spec/spec_helper.rb",
|
35
|
+
"templates/create_metadata.rb",
|
36
|
+
"templates/metadata.rb"
|
37
37
|
]
|
38
38
|
s.homepage = %q{http://github.com/riscfuture/has_metadata}
|
39
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
40
39
|
s.require_paths = ["lib"]
|
41
40
|
s.required_ruby_version = Gem::Requirement.new(">= 1.9")
|
42
41
|
s.rubygems_version = %q{1.3.7}
|
43
42
|
s.summary = %q{Reduce your table width by moving non-indexed columns to a separate metadata table}
|
44
43
|
s.test_files = [
|
45
44
|
"spec/has_metadata_spec.rb",
|
46
|
-
|
47
|
-
|
45
|
+
"spec/metadata_spec.rb",
|
46
|
+
"spec/spec_helper.rb"
|
48
47
|
]
|
49
48
|
|
50
49
|
if s.respond_to? :specification_version then
|
@@ -53,11 +52,26 @@ Gem::Specification.new do |s|
|
|
53
52
|
|
54
53
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
55
54
|
s.add_runtime_dependency(%q<rails>, [">= 3.0"])
|
55
|
+
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
56
|
+
s.add_development_dependency(%q<yard>, [">= 0"])
|
57
|
+
s.add_development_dependency(%q<RedCloth>, [">= 0"])
|
58
|
+
s.add_development_dependency(%q<sqlite3>, [">= 0"])
|
59
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
56
60
|
else
|
57
61
|
s.add_dependency(%q<rails>, [">= 3.0"])
|
62
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
63
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
64
|
+
s.add_dependency(%q<RedCloth>, [">= 0"])
|
65
|
+
s.add_dependency(%q<sqlite3>, [">= 0"])
|
66
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
58
67
|
end
|
59
68
|
else
|
60
69
|
s.add_dependency(%q<rails>, [">= 3.0"])
|
70
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
71
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
72
|
+
s.add_dependency(%q<RedCloth>, [">= 0"])
|
73
|
+
s.add_dependency(%q<sqlite3>, [">= 0"])
|
74
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
61
75
|
end
|
62
76
|
end
|
63
77
|
|
@@ -6,7 +6,7 @@ require 'rails/generators/migration'
|
|
6
6
|
class MetadataGenerator < Rails::Generators::Base
|
7
7
|
include Rails::Generators::Migration
|
8
8
|
|
9
|
-
source_root "#{File.dirname __FILE__}
|
9
|
+
source_root "#{File.dirname __FILE__}/../../templates"
|
10
10
|
|
11
11
|
def self.next_migration_number(dirname)
|
12
12
|
if ActiveRecord::Base.timestamped_migrations then
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module HasMetadata
|
2
|
+
|
3
|
+
# Base class of the {Metadata} model. Functionality is moved to this class to
|
4
|
+
# make changes to the model easier. See the @Metadata@ method for more
|
5
|
+
# information.
|
6
|
+
|
7
|
+
class Model < ActiveRecord::Base
|
8
|
+
set_table_name 'metadata'
|
9
|
+
serialize :data, Hash
|
10
|
+
|
11
|
+
after_initialize :initialize_data
|
12
|
+
before_save :nullify_empty_fields
|
13
|
+
|
14
|
+
validates :data,
|
15
|
+
presence: true
|
16
|
+
|
17
|
+
# @private
|
18
|
+
def set_fields(fields)
|
19
|
+
return self if @fields_set
|
20
|
+
@fields_set = true
|
21
|
+
|
22
|
+
fields.each do |name, _|
|
23
|
+
singleton_class.send(:define_method, name) { |default=nil| data.include?(name) ? data[name] : default }
|
24
|
+
singleton_class.send(:define_method, :"#{name}=") { |value| data[name] = value }
|
25
|
+
end
|
26
|
+
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def initialize_data
|
33
|
+
self.data ||= Hash.new
|
34
|
+
end
|
35
|
+
|
36
|
+
def nullify_empty_fields
|
37
|
+
data.each { |key, value| data[key] = nil if data[key].blank? }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/has_metadata.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
require 'metadata_generator'
|
1
|
+
require 'has_metadata/metadata_generator'
|
2
|
+
require 'has_metadata/model'
|
2
3
|
|
3
4
|
# @private
|
4
5
|
class Object
|
@@ -6,7 +7,7 @@ class Object
|
|
6
7
|
# Creates a deep copy of this object.
|
7
8
|
#
|
8
9
|
# @raise [TypeError] If the object cannot be deep-copied. All objects that can
|
9
|
-
#
|
10
|
+
# be marshalled can be deep-copied.
|
10
11
|
|
11
12
|
def deep_clone
|
12
13
|
Marshal.load Marshal.dump(self)
|
@@ -30,9 +31,12 @@ module HasMetadata
|
|
30
31
|
# key value.
|
31
32
|
#
|
32
33
|
# In addition to the normal @validates@ keys, you can also include a @:type@
|
33
|
-
# key to restrict values to certain classes
|
34
|
+
# key to restrict values to certain classes, or a @:default@ key to specify
|
35
|
+
# a value to return for the getter should none be set (normal default is
|
36
|
+
# @nil@).
|
34
37
|
#
|
35
|
-
# @param [Hash<Symbol, Hash>] fields A mapping of field names to their
|
38
|
+
# @param [Hash<Symbol, Hash>] fields A mapping of field names to their
|
39
|
+
# validation options (and/or the @:type@ key).
|
36
40
|
#
|
37
41
|
# @example Three metadata fields, one basic, one validated, and one type-checked.
|
38
42
|
# has_metadata(optional: true, required: { presence: true }, number: { type: Fixnum })
|
@@ -48,17 +52,23 @@ module HasMetadata
|
|
48
52
|
#define_method(:metadata_changed?) { metadata and metadata.changed? }
|
49
53
|
|
50
54
|
fields.each do |name, options|
|
51
|
-
delegate name, to: :metadata!
|
52
55
|
delegate :"#{name}=", to: :metadata!
|
53
|
-
|
56
|
+
|
54
57
|
if options.kind_of?(Hash) then
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
58
|
+
default = options.delete(:default)
|
59
|
+
define_method(name) { metadata!.send(name, default) }
|
60
|
+
|
61
|
+
unless options.empty?
|
62
|
+
type = options.delete(:type)
|
63
|
+
validate do |obj|
|
64
|
+
errors.add(name, :incorrect_type) unless
|
65
|
+
metadata_typecast(obj.send(name), type).kind_of?(type) or
|
66
|
+
((options[:allow_nil] and obj.send(name).nil?) or (options[:allow_blank] and obj.send(name).blank?))
|
67
|
+
end if type
|
68
|
+
validates(name, options) unless options.empty? or (options.keys - [ :allow_nil, :allow_blank ]).empty?
|
69
|
+
end
|
70
|
+
else
|
71
|
+
delegate name, to: :metadata!
|
62
72
|
end
|
63
73
|
end
|
64
74
|
end
|
@@ -103,7 +113,8 @@ module HasMetadata
|
|
103
113
|
super(pairs - fake_attributes)
|
104
114
|
end
|
105
115
|
|
106
|
-
# @return [Metadata] An existing associated {Metadata} instance, or new,
|
116
|
+
# @return [Metadata] An existing associated {Metadata} instance, or new,
|
117
|
+
# saved one if none was found.
|
107
118
|
|
108
119
|
def metadata!
|
109
120
|
if instance_variables.include?(:@metadata) then
|
data/spec/has_metadata_spec.rb
CHANGED
@@ -14,7 +14,8 @@ module SpecSupport
|
|
14
14
|
can_be_nil: { type: Date, allow_nil: true },
|
15
15
|
can_be_blank: { type: Date, allow_blank: true },
|
16
16
|
number: { numericality: true },
|
17
|
-
multiparam: { type: SpecSupport::ConstructorTester }
|
17
|
+
multiparam: { type: SpecSupport::ConstructorTester },
|
18
|
+
has_default: { default: 'default' }
|
18
19
|
})
|
19
20
|
end
|
20
21
|
end
|
@@ -53,6 +54,15 @@ describe HasMetadata do
|
|
53
54
|
|
54
55
|
@object.untyped.should be_nil
|
55
56
|
end
|
57
|
+
|
58
|
+
it "should return a default if one is specified" do
|
59
|
+
@object.has_default.should eql('default')
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should return nil if nil is stored and the default is not nil" do
|
63
|
+
@metadata.data[:has_default] = nil
|
64
|
+
@object.has_default.should eql(nil)
|
65
|
+
end
|
56
66
|
end
|
57
67
|
|
58
68
|
it "should make a setter for each field" do
|
data/spec/spec_helper.rb
CHANGED
data/templates/metadata.rb
CHANGED
@@ -7,36 +7,5 @@
|
|
7
7
|
#
|
8
8
|
# | @data@ | A hash of this metadata's contents (YAML serialized in the database). |
|
9
9
|
|
10
|
-
class Metadata <
|
11
|
-
set_table_name 'metadata'
|
12
|
-
serialize :data, Hash
|
13
|
-
|
14
|
-
after_initialize :initialize_data
|
15
|
-
before_save :nullify_empty_fields
|
16
|
-
|
17
|
-
validates :data,
|
18
|
-
presence: true
|
19
|
-
|
20
|
-
# @private
|
21
|
-
def set_fields(fields)
|
22
|
-
return self if @fields_set
|
23
|
-
@fields_set = true
|
24
|
-
|
25
|
-
fields.each do |name, _|
|
26
|
-
singleton_class.send(:define_method, name) { data[name] }
|
27
|
-
singleton_class.send(:define_method, :"#{name}=") { |value| data[name] = value }
|
28
|
-
end
|
29
|
-
|
30
|
-
self
|
31
|
-
end
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
def initialize_data
|
36
|
-
self.data ||= Hash.new
|
37
|
-
end
|
38
|
-
|
39
|
-
def nullify_empty_fields
|
40
|
-
data.each { |key, value| data[key] = nil if data[key].blank? }
|
41
|
-
end
|
10
|
+
class Metadata < HasMetadata::Model
|
42
11
|
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 1
|
7
|
+
- 1
|
7
8
|
- 0
|
8
|
-
|
9
|
-
version: 1.0.0
|
9
|
+
version: 1.1.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Tim Morgan
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-11-17 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -31,6 +31,71 @@ dependencies:
|
|
31
31
|
type: :runtime
|
32
32
|
prerelease: false
|
33
33
|
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: jeweler
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *id002
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: yard
|
49
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
version: "0"
|
57
|
+
type: :development
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: *id003
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: RedCloth
|
62
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
version: "0"
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: *id004
|
73
|
+
- !ruby/object:Gem::Dependency
|
74
|
+
name: sqlite3
|
75
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
segments:
|
81
|
+
- 0
|
82
|
+
version: "0"
|
83
|
+
type: :development
|
84
|
+
prerelease: false
|
85
|
+
version_requirements: *id005
|
86
|
+
- !ruby/object:Gem::Dependency
|
87
|
+
name: rspec
|
88
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
version: "0"
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: *id006
|
34
99
|
description: has_metadata lets you move non-indexed and weighty columns off of your big tables by creating a separate metadata table to store all this extra information. Works with Ruby 1.9. and Rails 3.0.
|
35
100
|
email: git@timothymorgan.info
|
36
101
|
executables: []
|
@@ -42,7 +107,6 @@ extra_rdoc_files:
|
|
42
107
|
- README.textile
|
43
108
|
files:
|
44
109
|
- .document
|
45
|
-
- .gitignore
|
46
110
|
- .rspec
|
47
111
|
- Gemfile
|
48
112
|
- Gemfile.lock
|
@@ -52,7 +116,8 @@ files:
|
|
52
116
|
- VERSION
|
53
117
|
- has_metadata.gemspec
|
54
118
|
- lib/has_metadata.rb
|
55
|
-
- lib/metadata_generator.rb
|
119
|
+
- lib/has_metadata/metadata_generator.rb
|
120
|
+
- lib/has_metadata/model.rb
|
56
121
|
- spec/has_metadata_spec.rb
|
57
122
|
- spec/metadata_spec.rb
|
58
123
|
- spec/spec_helper.rb
|
@@ -63,8 +128,8 @@ homepage: http://github.com/riscfuture/has_metadata
|
|
63
128
|
licenses: []
|
64
129
|
|
65
130
|
post_install_message:
|
66
|
-
rdoc_options:
|
67
|
-
|
131
|
+
rdoc_options: []
|
132
|
+
|
68
133
|
require_paths:
|
69
134
|
- lib
|
70
135
|
required_ruby_version: !ruby/object:Gem::Requirement
|
data/.gitignore
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
## MAC OS
|
2
|
-
.DS_Store
|
3
|
-
|
4
|
-
## TEXTMATE
|
5
|
-
*.tmproj
|
6
|
-
tmtags
|
7
|
-
|
8
|
-
## EMACS
|
9
|
-
*~
|
10
|
-
\#*
|
11
|
-
.\#*
|
12
|
-
|
13
|
-
## VIM
|
14
|
-
*.swp
|
15
|
-
|
16
|
-
## PROJECT::GENERAL
|
17
|
-
coverage
|
18
|
-
rdoc
|
19
|
-
pkg
|
20
|
-
.bundle
|
21
|
-
.rvmrc
|
22
|
-
test.sqlite
|
23
|
-
|
24
|
-
## PROJECT::DOCUMENTATION
|
25
|
-
.yardoc
|
26
|
-
doc
|