extend_at 0.2.3 → 0.2.4
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.
- data/README.markdown +60 -10
- data/extend_at.gemspec +1 -1
- data/lib/extend_at/version.rb +1 -1
- metadata +10 -10
data/README.markdown
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
This gem allows you to extend models without migrations: This way you can, i.e., develop your own content types, like in Drupal.
|
4
4
|
|
5
|
+
For example, if you want to create an administration panel to add columns to a model, for example, you are working on
|
6
|
+
a CMS, and you want to create a _"content type"_ and you need to set the _"columns"_ but you
|
7
|
+
don't want to migrate the database, then, you can see [this](https://github.com/anga/extend_at#tips) little tutorial.
|
8
|
+
|
5
9
|
## Status:
|
6
10
|
|
7
11
|
[](http://travis-ci.org/anga/extend_at)
|
@@ -252,14 +256,15 @@ Comparations:
|
|
252
256
|
### Belongs to
|
253
257
|
|
254
258
|
If you like to add a belongs_to relationship, you can do it in this way:
|
255
|
-
# app/models/toolbox.rb
|
256
|
-
class Toolbox
|
257
|
-
end
|
258
259
|
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
260
|
+
# app/models/toolbox.rb
|
261
|
+
class Toolbox
|
262
|
+
end
|
263
|
+
|
264
|
+
# app/model/tool.rb
|
265
|
+
class Tool
|
266
|
+
extend_at extra, columns => {}, :belongs_to => :toolbox
|
267
|
+
end
|
263
268
|
|
264
269
|
<code>:belongs_to</code> parametter accept
|
265
270
|
|
@@ -273,7 +278,7 @@ If you like to add a belongs_to relationship, you can do it in this way:
|
|
273
278
|
|
274
279
|
* Hash
|
275
280
|
|
276
|
-
:belongs_to => :onwer => {:class_name => "User"}
|
281
|
+
:belongs_to => {:onwer => {:class_name => "User"}}
|
277
282
|
|
278
283
|
For now, hash only accept
|
279
284
|
|
@@ -317,7 +322,7 @@ If you like to do something more dynamic, like create columns and validations de
|
|
317
322
|
columns[name.to_sym] = {
|
318
323
|
:type => eval(config.class_type),
|
319
324
|
:default => config.default_value,
|
320
|
-
:validate => get_validation(config
|
325
|
+
:validate => get_validation(config)
|
321
326
|
}
|
322
327
|
end
|
323
328
|
|
@@ -330,7 +335,52 @@ If you like to do something more dynamic, like create columns and validations de
|
|
330
335
|
end
|
331
336
|
end
|
332
337
|
|
333
|
-
|
338
|
+
How works?
|
339
|
+
|
340
|
+
serialize :columns_name
|
341
|
+
|
342
|
+
This make <code>columns_name</code> column work like YAML serialized object. In this case, is used to sotore an array of names of each column name.
|
343
|
+
(See [ActiveRecord::Base](http://api.rubyonrails.org/classes/ActiveRecord/Base.html))
|
344
|
+
|
345
|
+
extend_at :extra, :columns => :get_columns
|
346
|
+
|
347
|
+
This line will use the function <code>get_columns</code> to get the information about each column dynamically.
|
348
|
+
This function returns a hash with the information about each column.
|
349
|
+
|
350
|
+
columns_name.each do |name|
|
351
|
+
#...
|
352
|
+
end
|
353
|
+
|
354
|
+
Iterate through each column stored in the column <code>columns_name</code>.
|
355
|
+
|
356
|
+
config = ColumConfig.where(:user_id => self.id, :column => name).first
|
357
|
+
|
358
|
+
Search the column configuration stored in a separated model. By this way, we can configura each column easily, we can create a view to create columns and configure it easily.
|
359
|
+
|
360
|
+
columns[name.to_sym] = {
|
361
|
+
:type => eval(config.class_type),
|
362
|
+
:default => config.default_value,
|
363
|
+
:validate => get_validation(config)
|
364
|
+
}
|
365
|
+
|
366
|
+
This lines configure the column.
|
367
|
+
|
368
|
+
:type => eval(config.class_type),
|
369
|
+
|
370
|
+
The model <code>ColumConfig</code> have a string column named <code>class_type</code>, can be <code>":integer"</code> or <code>"Fixnum"</code>.
|
371
|
+
|
372
|
+
:default => config.default_value,
|
373
|
+
|
374
|
+
The model <code>ColumConfig</code> have a serialized column named <code>default_valuee</code>, in this way we can sotre integer values, boolean, strings or datetime and time values without problems.
|
375
|
+
|
376
|
+
:validate => get_validation(config.validation)
|
377
|
+
|
378
|
+
This line execute the function <code>get_validation</code> to get a <code>Proc</code> with the validation code.
|
379
|
+
This function can use a case/when for select the correct function or use the data of the model <code>config</code> to create a function.
|
380
|
+
|
381
|
+
columns
|
382
|
+
|
383
|
+
Finally we return the colums configuration.
|
334
384
|
|
335
385
|
## Bugs, recomendation, etc
|
336
386
|
|
data/extend_at.gemspec
CHANGED
@@ -19,10 +19,10 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
21
|
s.add_runtime_dependency 'rails', '~> 3.1'
|
22
|
+
s.add_runtime_dependency "activesupport", '~> 3.1'
|
22
23
|
s.add_development_dependency "rspec", '~> 2.8'
|
23
24
|
s.add_development_dependency "rspec-core", '~> 2.8'
|
24
25
|
s.add_development_dependency "rspec-expectations", '~> 2.8'
|
25
|
-
s.add_development_dependency "activesupport", '~> 3.1'
|
26
26
|
# s.add_development_dependency "rspec-mocks", '~> 2.8.0'
|
27
27
|
s.add_development_dependency "database_cleaner", "~> 0.8"
|
28
28
|
|
data/lib/extend_at/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: extend_at
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -28,23 +28,23 @@ dependencies:
|
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '3.1'
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
|
-
name:
|
31
|
+
name: activesupport
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
35
35
|
- - ~>
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: '
|
38
|
-
type: :
|
37
|
+
version: '3.1'
|
38
|
+
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
43
|
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: '
|
45
|
+
version: '3.1'
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
|
-
name: rspec
|
47
|
+
name: rspec
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
@@ -60,7 +60,7 @@ dependencies:
|
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '2.8'
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
|
-
name: rspec-
|
63
|
+
name: rspec-core
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
65
65
|
none: false
|
66
66
|
requirements:
|
@@ -76,13 +76,13 @@ dependencies:
|
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '2.8'
|
78
78
|
- !ruby/object:Gem::Dependency
|
79
|
-
name:
|
79
|
+
name: rspec-expectations
|
80
80
|
requirement: !ruby/object:Gem::Requirement
|
81
81
|
none: false
|
82
82
|
requirements:
|
83
83
|
- - ~>
|
84
84
|
- !ruby/object:Gem::Version
|
85
|
-
version: '
|
85
|
+
version: '2.8'
|
86
86
|
type: :development
|
87
87
|
prerelease: false
|
88
88
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -90,7 +90,7 @@ dependencies:
|
|
90
90
|
requirements:
|
91
91
|
- - ~>
|
92
92
|
- !ruby/object:Gem::Version
|
93
|
-
version: '
|
93
|
+
version: '2.8'
|
94
94
|
- !ruby/object:Gem::Dependency
|
95
95
|
name: database_cleaner
|
96
96
|
requirement: !ruby/object:Gem::Requirement
|