-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
109 lines (72 loc) · 2.58 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
CustomAttributes
================
(alpha release)
1)
Adds custom attributes through a CustomAttribute Model, but behaves like standard AR attributes.
Has support some basic validations.
2)
CustomValueWithUnit supports composed attributes of value and unit.
Has support for validation of unit compatibility.
3)
a DSL for creating attributed models, which brings also support for nested Custom Objects, wich are mapped to plain 'AR-Row-Models'.
Brings a taste of document-based DBs like Mongo or CloudDB to ActiveRecord.
DSL Example
===========
class Design < ActiveRecord::Base
acts_as_custom_attribute_container
has_custom :width, :height, :unit=>'cm'
has_custom :colors do
has_custom :name, :string
end
has_custom :designer do
has_custom :name, :string
has_custom :website, :string
has_custom :biography, :string #todo: :text
end
end
Example
=======
(alternatively you can use a more verbose form)
class Item < ActiveRecord::Base
acts_as_custom_attribute_container
end
class CarpetItem < Item
has_custom_attributes :width, :length, :height, :class=>CustomValueWithUnit, :unit=>'cm'
has_custom_attribute :sqm, :class=>CustomValueWithUnit, :unit=>'m**2'
has_custom_attribute :weight, :class=>CustomValueWithUnit, :unit=>'kg'
end
class ShirtItem < Item
has_custom_attribute :size, :class=>CustomString
has_custom_attribute :weight, :class=>CustomValueWithUnit, :unit=>'kg'
validates_presence_of :size
end
Migrations ( sorry, no generator yet )
==========
create_table "custom_attributes", :force => true do |t|
t.string "name"
t.integer "customizable_id"
t.string "customizable_type"
t.datetime "created_at"
t.datetime "updated_at"
t.decimal "value_value", :precision => 20, :scale => 10
t.string "value_unit"
t.string "type"
t.boolean "value_boolean"
end
add_index "custom_attributes", ["customizable_id", "customizable_type", "name"], :name => "index_on_custom_attributes_id_and_type_and_name"
add_index "custom_attributes", ["customizable_id", "customizable_type"], :name => "index_on_custom_attributes_id_and_type"
create_table "custom_objects", :force => true do |t|
t.string "type"
t.datetime "created_at"
t.datetime "updated_at"
t.string "customizable_type"
t.integer "customizable_id"
end
Todo
====
More dedicated custom_xx tables, at the moment we waste some space in the db, but should be no problem for normal apps.
Credits
=======
We use Stick::Units for the CustomValueWithUnit part
http://stick.rubyforge.org/
Copyright (c) 2010 [Ninja Concept/Marco Sehrer], released under the MIT license