trax_model 0.0.92 → 0.0.93

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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +0 -1
  3. data/README.md +227 -86
  4. data/lib/trax.rb +0 -1
  5. data/lib/trax/model.rb +23 -29
  6. data/lib/trax/model/attributes.rb +3 -1
  7. data/lib/trax/model/attributes/attribute.rb +11 -0
  8. data/lib/trax/model/attributes/definitions.rb +16 -0
  9. data/lib/trax/model/attributes/errors.rb +8 -0
  10. data/lib/trax/model/attributes/fields.rb +74 -0
  11. data/lib/trax/model/attributes/mixin.rb +48 -19
  12. data/lib/trax/model/attributes/type.rb +4 -0
  13. data/lib/trax/model/attributes/types/array.rb +8 -25
  14. data/lib/trax/model/attributes/types/boolean.rb +51 -0
  15. data/lib/trax/model/attributes/types/enum.rb +53 -12
  16. data/lib/trax/model/attributes/types/json.rb +36 -33
  17. data/lib/trax/model/attributes/types/string.rb +50 -0
  18. data/lib/trax/model/attributes/types/uuid_array.rb +17 -28
  19. data/lib/trax/model/attributes/value.rb +16 -0
  20. data/lib/trax/model/errors.rb +7 -0
  21. data/lib/trax/model/mixins.rb +11 -0
  22. data/lib/trax/model/mixins/field_scopes.rb +60 -0
  23. data/lib/trax/model/mixins/id_scopes.rb +36 -0
  24. data/lib/trax/model/mixins/sort_by_scopes.rb +25 -0
  25. data/lib/trax/model/railtie.rb +1 -0
  26. data/lib/trax/model/scopes.rb +16 -0
  27. data/lib/trax/model/struct.rb +168 -14
  28. data/lib/trax/model/unique_id.rb +14 -21
  29. data/lib/trax/model/uuid.rb +1 -1
  30. data/lib/trax/validators/enum_attribute_validator.rb +9 -0
  31. data/lib/trax/validators/future_validator.rb +1 -1
  32. data/lib/trax/validators/json_attribute_validator.rb +3 -3
  33. data/lib/trax/validators/string_attribute_validator.rb +17 -0
  34. data/lib/trax_model/version.rb +1 -1
  35. data/spec/db/database.yml +16 -0
  36. data/spec/db/schema/default_tables.rb +68 -0
  37. data/spec/db/schema/pg_tables.rb +27 -0
  38. data/spec/spec_helper.rb +20 -3
  39. data/spec/support/models.rb +123 -0
  40. data/spec/support/pg/models.rb +103 -0
  41. data/spec/trax/model/attributes/fields_spec.rb +88 -0
  42. data/spec/trax/model/attributes/types/enum_spec.rb +51 -0
  43. data/spec/trax/model/attributes/types/json_spec.rb +107 -0
  44. data/spec/trax/model/attributes_spec.rb +13 -0
  45. data/spec/trax/model/errors_spec.rb +1 -2
  46. data/spec/trax/model/mixins/field_scopes_spec.rb +7 -0
  47. data/spec/trax/model/struct_spec.rb +1 -1
  48. data/spec/trax/model/unique_id_spec.rb +1 -3
  49. data/spec/trax/validators/url_validator_spec.rb +1 -1
  50. data/trax_model.gemspec +4 -4
  51. metadata +57 -19
  52. data/lib/trax/model/config.rb +0 -16
  53. data/lib/trax/model/validators.rb +0 -15
  54. data/lib/trax/validators/enum_validator.rb +0 -16
  55. data/spec/support/schema.rb +0 -151
  56. data/spec/trax/model/config_spec.rb +0 -13
@@ -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
@@ -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