trax_model 0.0.92 → 0.0.93
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -1
- data/README.md +227 -86
- data/lib/trax.rb +0 -1
- data/lib/trax/model.rb +23 -29
- data/lib/trax/model/attributes.rb +3 -1
- data/lib/trax/model/attributes/attribute.rb +11 -0
- data/lib/trax/model/attributes/definitions.rb +16 -0
- data/lib/trax/model/attributes/errors.rb +8 -0
- data/lib/trax/model/attributes/fields.rb +74 -0
- data/lib/trax/model/attributes/mixin.rb +48 -19
- data/lib/trax/model/attributes/type.rb +4 -0
- data/lib/trax/model/attributes/types/array.rb +8 -25
- data/lib/trax/model/attributes/types/boolean.rb +51 -0
- data/lib/trax/model/attributes/types/enum.rb +53 -12
- data/lib/trax/model/attributes/types/json.rb +36 -33
- data/lib/trax/model/attributes/types/string.rb +50 -0
- data/lib/trax/model/attributes/types/uuid_array.rb +17 -28
- data/lib/trax/model/attributes/value.rb +16 -0
- data/lib/trax/model/errors.rb +7 -0
- data/lib/trax/model/mixins.rb +11 -0
- data/lib/trax/model/mixins/field_scopes.rb +60 -0
- data/lib/trax/model/mixins/id_scopes.rb +36 -0
- data/lib/trax/model/mixins/sort_by_scopes.rb +25 -0
- data/lib/trax/model/railtie.rb +1 -0
- data/lib/trax/model/scopes.rb +16 -0
- data/lib/trax/model/struct.rb +168 -14
- data/lib/trax/model/unique_id.rb +14 -21
- data/lib/trax/model/uuid.rb +1 -1
- data/lib/trax/validators/enum_attribute_validator.rb +9 -0
- data/lib/trax/validators/future_validator.rb +1 -1
- data/lib/trax/validators/json_attribute_validator.rb +3 -3
- data/lib/trax/validators/string_attribute_validator.rb +17 -0
- data/lib/trax_model/version.rb +1 -1
- data/spec/db/database.yml +16 -0
- data/spec/db/schema/default_tables.rb +68 -0
- data/spec/db/schema/pg_tables.rb +27 -0
- data/spec/spec_helper.rb +20 -3
- data/spec/support/models.rb +123 -0
- data/spec/support/pg/models.rb +103 -0
- data/spec/trax/model/attributes/fields_spec.rb +88 -0
- data/spec/trax/model/attributes/types/enum_spec.rb +51 -0
- data/spec/trax/model/attributes/types/json_spec.rb +107 -0
- data/spec/trax/model/attributes_spec.rb +13 -0
- data/spec/trax/model/errors_spec.rb +1 -2
- data/spec/trax/model/mixins/field_scopes_spec.rb +7 -0
- data/spec/trax/model/struct_spec.rb +1 -1
- data/spec/trax/model/unique_id_spec.rb +1 -3
- data/spec/trax/validators/url_validator_spec.rb +1 -1
- data/trax_model.gemspec +4 -4
- metadata +57 -19
- data/lib/trax/model/config.rb +0 -16
- data/lib/trax/model/validators.rb +0 -15
- data/lib/trax/validators/enum_validator.rb +0 -16
- data/spec/support/schema.rb +0 -151
- data/spec/trax/model/config_spec.rb +0 -13
data/lib/trax/model/config.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
module Trax
|
2
|
-
module Model
|
3
|
-
class Config < ::Hashie::Dash
|
4
|
-
property :uuid_prefix, :default => nil
|
5
|
-
property :uuid_column, :default => :id
|
6
|
-
|
7
|
-
def uuid_prefix=(prefix)
|
8
|
-
if prefix.length != 2 || prefix.chars.any?{|char| char !~ /[0-9a-f]/ }
|
9
|
-
raise ::Trax::Model::Errors::InvalidPrefixForUUID.new(:prefix => prefix)
|
10
|
-
end
|
11
|
-
|
12
|
-
self[:uuid_prefix] = ::Trax::Model::UUIDPrefix.new(prefix)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module Trax
|
2
|
-
module Model
|
3
|
-
module Validators
|
4
|
-
extend ::ActiveSupport::Autoload
|
5
|
-
|
6
|
-
autoload :BooleanValidator
|
7
|
-
autoload :EmailValidator
|
8
|
-
autoload :EnumValidator
|
9
|
-
autoload :Frozen
|
10
|
-
autoload :FutureDate
|
11
|
-
autoload :Subdomain
|
12
|
-
autoload :UrlValidator
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
class EnumValidator < ActiveModel::EachValidator
|
2
|
-
def validate_each(object, attribute, value)
|
3
|
-
enum_attribute = object.class.trax_attribute_fields[:enum][attribute]
|
4
|
-
|
5
|
-
unless value.is_a?(enum_attribute) && value.valid?
|
6
|
-
if value.is_a?(enum_attribute)
|
7
|
-
value.errors.messages.each_pair do |k,v|
|
8
|
-
v = v.join(", ") if v.is_a?(Array)
|
9
|
-
object.errors["#{attribute}.#{k}"] = v
|
10
|
-
end
|
11
|
-
else
|
12
|
-
object.errors[attribute] = "#{v} is not an allowed value"
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
data/spec/support/schema.rb
DELETED
@@ -1,151 +0,0 @@
|
|
1
|
-
require 'active_record'
|
2
|
-
|
3
|
-
ActiveRecord::Base.establish_connection(
|
4
|
-
:adapter => "sqlite3",
|
5
|
-
:database => "spec/test.db"
|
6
|
-
)
|
7
|
-
|
8
|
-
ActiveRecord::Base.connection.tables.each do |table|
|
9
|
-
ActiveRecord::Base.connection.drop_table(table)
|
10
|
-
end
|
11
|
-
|
12
|
-
ActiveRecord::Schema.define(:version => 1) do
|
13
|
-
create_table "products", :force => true do |t|
|
14
|
-
t.string "name"
|
15
|
-
t.integer "category_id"
|
16
|
-
t.integer "user_id"
|
17
|
-
t.decimal "price"
|
18
|
-
t.integer "in_stock_quantity"
|
19
|
-
t.integer "on_order_quantity"
|
20
|
-
t.boolean "active"
|
21
|
-
t.string "uuid"
|
22
|
-
t.datetime "created_at", :null => false
|
23
|
-
t.datetime "updated_at", :null => false
|
24
|
-
end
|
25
|
-
|
26
|
-
create_table "messages", :force => true do |t|
|
27
|
-
t.string "title"
|
28
|
-
t.text "body"
|
29
|
-
t.integer "status"
|
30
|
-
t.string "uuid"
|
31
|
-
t.boolean "deleted"
|
32
|
-
t.datetime "deleted_at"
|
33
|
-
t.datetime "deliver_at"
|
34
|
-
t.datetime "created_at", :null => false
|
35
|
-
t.datetime "updated_at", :null => false
|
36
|
-
end
|
37
|
-
|
38
|
-
create_table "widgets", :force => true do |t|
|
39
|
-
t.string "uuid"
|
40
|
-
t.string "email_address"
|
41
|
-
t.string "subdomain"
|
42
|
-
t.string "website"
|
43
|
-
t.integer "status"
|
44
|
-
t.datetime "created_at", :null => false
|
45
|
-
t.datetime "updated_at", :null => false
|
46
|
-
end
|
47
|
-
|
48
|
-
create_table "things", :force => true do |t|
|
49
|
-
t.string "name"
|
50
|
-
t.string "uuid"
|
51
|
-
t.datetime "created_at", :null => false
|
52
|
-
t.datetime "updated_at", :null => false
|
53
|
-
end
|
54
|
-
|
55
|
-
create_table "people", :force => true do |t|
|
56
|
-
t.string "name"
|
57
|
-
t.string "uuid"
|
58
|
-
t.datetime "created_at", :null => false
|
59
|
-
t.datetime "updated_at", :null => false
|
60
|
-
end
|
61
|
-
|
62
|
-
create_table "staplers", :force => true do |t|
|
63
|
-
t.string "name"
|
64
|
-
t.string "type"
|
65
|
-
t.integer "attribute_set_id"
|
66
|
-
t.datetime "created_at", :null => false
|
67
|
-
t.datetime "updated_at", :null => false
|
68
|
-
end
|
69
|
-
|
70
|
-
create_table "swingline_stapler_attribute_sets", :force => true do |t|
|
71
|
-
t.float "speed"
|
72
|
-
t.string "owner"
|
73
|
-
|
74
|
-
t.datetime "created_at", :null => false
|
75
|
-
t.datetime "updated_at", :null => false
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
class Product < ::ActiveRecord::Base
|
80
|
-
include ::Trax::Model
|
81
|
-
|
82
|
-
mixins :unique_id => {
|
83
|
-
:uuid_column => "uuid",
|
84
|
-
:uuid_prefix => "1a"
|
85
|
-
}
|
86
|
-
end
|
87
|
-
|
88
|
-
class Widget < ::ActiveRecord::Base
|
89
|
-
include ::Trax::Model
|
90
|
-
|
91
|
-
mixins :unique_id => {
|
92
|
-
:uuid_column => "uuid",
|
93
|
-
:uuid_prefix => "2a"
|
94
|
-
}
|
95
|
-
|
96
|
-
validates :subdomain, :subdomain => true, :allow_nil => true
|
97
|
-
validates :email_address, :email => true, :allow_nil => true
|
98
|
-
validates :website, :url => true, :allow_nil => true
|
99
|
-
end
|
100
|
-
|
101
|
-
class Message < ::ActiveRecord::Base
|
102
|
-
include ::Trax::Model
|
103
|
-
|
104
|
-
mixins :unique_id => { :uuid_column => "uuid", :uuid_prefix => "3a" },
|
105
|
-
:freezable => true,
|
106
|
-
:restorable => { :field => :deleted }
|
107
|
-
|
108
|
-
enum :status => [ :queued, :scheduled, :delivered, :failed_delivery ]
|
109
|
-
|
110
|
-
default_value_for :status do
|
111
|
-
self.statuses[:queued]
|
112
|
-
end
|
113
|
-
|
114
|
-
validates :deliver_at, :future => true, :allow_nil => true
|
115
|
-
|
116
|
-
freezable_by_enum :status => [ :delivered, :failed_delivery ]
|
117
|
-
end
|
118
|
-
|
119
|
-
class Thing < ::ActiveRecord::Base
|
120
|
-
include ::Trax::Model
|
121
|
-
|
122
|
-
mixins :unique_id => { :uuid_column => "uuid", :uuid_prefix => "4a" }
|
123
|
-
end
|
124
|
-
|
125
|
-
class Person < ::ActiveRecord::Base
|
126
|
-
include ::Trax::Model
|
127
|
-
|
128
|
-
mixins :unique_id => { :uuid_column => "uuid", :uuid_prefix => "5a" }
|
129
|
-
end
|
130
|
-
|
131
|
-
class Stapler < ::ActiveRecord::Base
|
132
|
-
include ::Trax::Model
|
133
|
-
end
|
134
|
-
|
135
|
-
class SwinglineStapler < ::Stapler
|
136
|
-
include ::Trax::Model::STI::Attributes
|
137
|
-
end
|
138
|
-
|
139
|
-
class SwinglineStaplerAttributeSet < ::ActiveRecord::Base
|
140
|
-
end
|
141
|
-
|
142
|
-
require 'trax/model/struct'
|
143
|
-
|
144
|
-
class StoreCategory < ::Trax::Model::Struct
|
145
|
-
property :name
|
146
|
-
|
147
|
-
struct_property :meta_attributes do
|
148
|
-
property :description
|
149
|
-
property :keywords
|
150
|
-
end
|
151
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ::Trax::Model::Config do
|
4
|
-
describe "uuid_prefix" do
|
5
|
-
context "bad prefixes" do
|
6
|
-
["a", "1p", "a1a", "bl", "1", "111"].each do |prefix|
|
7
|
-
it "raises error when passed hex incompatible prefix #{prefix}" do
|
8
|
-
expect{ described_class.new(:uuid_prefix => prefix).to_raise_error }
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|