sdl 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a6e61a1d5604a66b42b6fb6c1d9ef23cafe16f82
4
- data.tar.gz: 9c0aed1be31e2fd105bdf4797aae965a2470c9cf
3
+ metadata.gz: f3c0c72e2ceb5b542143447458c5428edf813ae3
4
+ data.tar.gz: 74287f31894980163d4f623578f72ded367dc480
5
5
  SHA512:
6
- metadata.gz: c507bebf2605c7dd156219e5ec791660279daf1de15d05cdffcbe5ed2142888c62b657033d6c2b7015565a4824cf5d5282df8919f63169559e9d9d5965c7ddbc
7
- data.tar.gz: 3f0982e9b1785c24a7a5f619bdaa7910f9559310a31008157a9043b2a4dce68172c21b01f4da11992e4022bbb3f711c9feac54ef4ad584cc8cf42bddc9e46375
6
+ metadata.gz: 9fb06fcea7e7cb5c7eaa711d3c57269508257246afbb7e9eee6c73bfdfb1159c4d30bb3858ced2c50bd3f6fd0ecfbd2fb5d4016c0d9829cbdc28c3709c875b32
7
+ data.tar.gz: 83bec3ca9b3c0d44aaf4cd82b3fafb1425e18c04637463deb0645b476729570f9deee94d338a97a892023041fb0f30fffa738aef4e4cbcc911fb67546e206224
@@ -18,6 +18,24 @@ module SDL
18
18
  @options = options
19
19
  end
20
20
 
21
+ # Indicates that this is an {Attribute}
22
+ # @return [Boolean]
23
+ def attribute?
24
+ !enum? && !association? && !attachment?
25
+ end
26
+
27
+ # Indicates that this is an {Attachment}
28
+ # @return [Boolean]
29
+ def attachment?
30
+ has_one_attached? || has_many_attached?
31
+ end
32
+
33
+ # Indicates that this is an {Association}
34
+ # @return [Boolean]
35
+ def association?
36
+ has_one? || has_many? || belongs_to?
37
+ end
38
+
21
39
  # @!method id?
22
40
  # Indicates that this is an {Attribute} whose type is `:id`
23
41
  # @return [Boolean]
@@ -1,4 +1,3 @@
1
- require "sdl/fields"
2
1
  require "sdl/attribute"
3
2
  require "sdl/enum"
4
3
  require "sdl/association"
@@ -10,6 +9,10 @@ module SDL
10
9
  # @return [String]
11
10
  attr_reader :name
12
11
 
12
+ # All of the fields that have been registered
13
+ # @return [Array<Field>]
14
+ attr_reader :fields
15
+
13
16
  # Any additional options
14
17
  # @return [Hash]
15
18
  attr_reader :options
@@ -22,12 +25,6 @@ module SDL
22
25
  instance_eval(&block) if block_given?
23
26
  end
24
27
 
25
- # All of the fields that have been registered
26
- # @return [Fields]
27
- def fields
28
- Fields.new(@fields)
29
- end
30
-
31
28
  # Adds an {Attribute} to the model
32
29
  # @param name [Symbol]
33
30
  # @param type [Symbol]
@@ -134,5 +131,77 @@ module SDL
134
131
  attribute :created_at, :datetime, required: true
135
132
  attribute :updated_at, :datetime, required: true
136
133
  end
134
+
135
+ # Get all {Attribute} fields
136
+ # @return [Array<Attribute>]
137
+ def attribute_fields
138
+ fields.grep Attribute
139
+ end
140
+
141
+ # Get all {Association} fields
142
+ # @return [Array<Association>]
143
+ def association_fields
144
+ fields.grep Association
145
+ end
146
+
147
+ # Get all {Attachment} fields
148
+ # @return [Array<Attachment>]
149
+ def attachment_fields
150
+ fields.grep Attachment
151
+ end
152
+
153
+ # @!method id_fields
154
+ # Get all {Attribute} fields whose type is `:id`
155
+ # @return [Array<Attribute>]
156
+ # @!method string_fields
157
+ # Get all {Attribute} fields whose type is `:string`
158
+ # @return [Array<Attribute>]
159
+ # @!method boolean_fields
160
+ # Get all {Attribute} fields whose type is `:boolean`
161
+ # @return [Array<Attribute>]
162
+ # @!method integer_fields
163
+ # Get all {Attribute} fields whose type is `:integer`
164
+ # @return [Array<Attribute>]
165
+ # @!method float_fields
166
+ # Get all {Attribute} fields whose type is `:float`
167
+ # @return [Array<Attribute>]
168
+ # @!method decimal_fields
169
+ # Get all {Attribute} fields whose type is `:decimal`
170
+ # @return [Array<Attribute>]
171
+ # @!method date_fields
172
+ # Get all {Attribute} fields whose type is `:date`
173
+ # @return [Array<Attribute>]
174
+ # @!method datetime_fields
175
+ # Get all {Attribute} fields whose type is `:datetime`
176
+ # @return [Array<Attribute>]
177
+ # @!method text_fields
178
+ # Get all {Attribute} fields whose type is `:text`
179
+ # @return [Array<Attribute>]
180
+ # @!method binary_fields
181
+ # Get all {Attribute} fields whose type is `:binary`
182
+ # @return [Array<Attribute>]
183
+ # @!method enum_fields
184
+ # Get all {Enum} fields
185
+ # @return [Array<Enum>]
186
+ # @!method belongs_to_fields
187
+ # Get all {Association::BelongsTo} fields
188
+ # @return [Array<Association::BelongsTo>]
189
+ # @!method has_one_fields
190
+ # Get all {Association::HasOne} fields
191
+ # @return [Array<Assocation::HasOne>]
192
+ # @!method has_many_fields
193
+ # Get all {Association::HasMany} fields
194
+ # @return [Array<Association::HasMany>]
195
+ # @!method has_one_attached_fields
196
+ # Get all {Attachment::HasOne} fields
197
+ # @return [Array<Attachment::HasOne>]
198
+ # @!method has_many_attached_fields
199
+ # Get all {Attachment::HasMany} fields
200
+ # @return [Array<Attachment::HasMany>]
201
+ TYPES.each do |meth|
202
+ define_method "#{meth}_fields" do
203
+ fields.select { |field| field.type == meth }
204
+ end
205
+ end
137
206
  end
138
207
  end
@@ -37,7 +37,7 @@ module SDL
37
37
  def depsort!
38
38
  each_node = models.method(:each)
39
39
  each_child = lambda do |model, &block|
40
- belongs_to = model.fields.belongs_to.map(&:model_name)
40
+ belongs_to = model.belongs_to_fields.map(&:model_name)
41
41
  children = models.select { |m| belongs_to.include?(m.name) }
42
42
  children.each(&block)
43
43
  end
@@ -1,3 +1,3 @@
1
1
  module SDL
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sdl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ray Zane
@@ -104,7 +104,6 @@ files:
104
104
  - lib/sdl/attribute.rb
105
105
  - lib/sdl/enum.rb
106
106
  - lib/sdl/field.rb
107
- - lib/sdl/fields.rb
108
107
  - lib/sdl/model.rb
109
108
  - lib/sdl/parser.rb
110
109
  - lib/sdl/schema.rb
@@ -1,103 +0,0 @@
1
- require "sdl/types"
2
- require "sdl/field"
3
- require "sdl/attribute"
4
- require "sdl/enum"
5
- require "sdl/association"
6
- require "sdl/attachment"
7
-
8
- module SDL
9
- # All fields of a {Model}
10
- class Fields
11
- include Enumerable
12
-
13
- # @api private
14
- def initialize(fields)
15
- @fields = fields
16
- end
17
-
18
- # Get a field by index
19
- # @param index [Integer]
20
- # @return [Field,nil]
21
- def [](index)
22
- @fields[index]
23
- end
24
-
25
- # Iterate over all fields
26
- # @yield [Field]
27
- def each(&block)
28
- @fields.each(&block)
29
- end
30
-
31
- # Get all instances of {Attribute}
32
- # @return [Array<Attribute>]
33
- def attributes
34
- grep Attribute
35
- end
36
-
37
- # Get all instances of {Association}
38
- # @return [Array<Association>]
39
- def associations
40
- grep Association
41
- end
42
-
43
- # Get all instances of {Attachment}
44
- # @return [Array<Attachment>]
45
- def attachments
46
- grep Attachment
47
- end
48
-
49
- # @!method id
50
- # Get all instances of {Attribute} whose type is `:id`
51
- # @return [Array<Attribute>]
52
- # @!method string
53
- # Get all instances of {Attribute} whose type is `:string`
54
- # @return [Array<Attribute>]
55
- # @!method boolean
56
- # Get all instances of {Attribute} whose type is `:boolean`
57
- # @return [Array<Attribute>]
58
- # @!method integer
59
- # Get all instances of {Attribute} whose type is `:integer`
60
- # @return [Array<Attribute>]
61
- # @!method float
62
- # Get all instances of {Attribute} whose type is `:float`
63
- # @return [Array<Attribute>]
64
- # @!method decimal
65
- # Get all instances of {Attribute} whose type is `:decimal`
66
- # @return [Array<Attribute>]
67
- # @!method date
68
- # Get all instances of {Attribute} whose type is `:date`
69
- # @return [Array<Attribute>]
70
- # @!method datetime
71
- # Get all instances of {Attribute} whose type is `:datetime`
72
- # @return [Array<Attribute>]
73
- # @!method text
74
- # Get all instances of {Attribute} whose type is `:text`
75
- # @return [Array<Attribute>]
76
- # @!method binary
77
- # Get all instances of {Attribute} whose type is `:binary`
78
- # @return [Array<Attribute>]
79
- # @!method enum
80
- # Get all instances of {Enum}
81
- # @return [Array<Enum>]
82
- # @!method belongs_to
83
- # Get all instances of {Association::BelongsTo}
84
- # @return [Array<Association::BelongsTo>]
85
- # @!method has_one
86
- # Get all instances of {Association::HasOne}
87
- # @return [Array<Assocation::HasOne>]
88
- # @!method has_many
89
- # Get all instances of {Association::HasMany}
90
- # @return [Array<Association::HasMany>]
91
- # @!method has_one_attached
92
- # Indicates that this is an {Attachment::HasOne}
93
- # @return [Array<Attachment::HasOne>]
94
- # @!method has_many_attached
95
- # Indicates that this is an {Attachment::HasMany}
96
- # @return [Array<Attachment::HasMany>]
97
- TYPES.each do |meth|
98
- define_method meth do
99
- select { |field| field.type == meth }
100
- end
101
- end
102
- end
103
- end