extend_at 0.0.2 → 0.0.3
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 +29 -25
- data/extend_at.gemspec +2 -2
- data/lib/extend_at/version.rb +1 -1
- metadata +6 -6
data/README.markdown
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Extend at
|
2
2
|
|
3
|
-
This gem allows you to extend
|
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
5
|
## Installation
|
6
6
|
|
@@ -12,11 +12,11 @@ Add in your Gemfile:
|
|
12
12
|
|
13
13
|
## Usage
|
14
14
|
|
15
|
-
|
15
|
+
You only need to add the next line in your model.
|
16
16
|
|
17
|
-
<code>extend_at :
|
17
|
+
<code>extend_at :extra</code>
|
18
18
|
|
19
|
-
The column <code>
|
19
|
+
The column <code>extra</code> must be string or text.
|
20
20
|
|
21
21
|
For example:
|
22
22
|
|
@@ -28,30 +28,30 @@ Now you can create extra attributes:
|
|
28
28
|
|
29
29
|
user.extra.private_photos = true
|
30
30
|
user.extra.subscribe_to_news = false
|
31
|
-
user.extra.
|
31
|
+
user.extra.profile_description = ''
|
32
32
|
user.save
|
33
33
|
|
34
|
-
|
34
|
+
This is the same:
|
35
35
|
|
36
36
|
user.extra_private_photos = true
|
37
37
|
user.extra_subscribe_to_news = false
|
38
|
-
user.
|
38
|
+
user.extra_profile_description = ''
|
39
39
|
user.save
|
40
40
|
|
41
41
|
Or:
|
42
42
|
|
43
43
|
user[:extra_private_photos] = true
|
44
44
|
user[:extra_subscribe_to_news] = false
|
45
|
-
user[:
|
45
|
+
user[:extra_profile_description] = ''
|
46
46
|
user.save
|
47
47
|
|
48
48
|
### Columns configuration
|
49
49
|
|
50
|
-
You can
|
50
|
+
You can configure each column.
|
51
51
|
|
52
52
|
#### Set column type
|
53
53
|
|
54
|
-
You can set the type
|
54
|
+
You can set the colum's type.
|
55
55
|
|
56
56
|
class User < ActiveRecord::Base
|
57
57
|
extend_at :extra, :columns => {
|
@@ -59,7 +59,7 @@ You can set the type of the colum.
|
|
59
59
|
:type => :boolean
|
60
60
|
}, :age => {
|
61
61
|
:type => :get_type
|
62
|
-
}, :
|
62
|
+
}, :profile_description => {
|
63
63
|
:type => lambda {
|
64
64
|
String
|
65
65
|
}
|
@@ -92,11 +92,11 @@ You can use any class, but if you need use boolean values, you must use :boolean
|
|
92
92
|
}, :age => {
|
93
93
|
:type => :get_type,
|
94
94
|
:default => 1
|
95
|
-
}, :
|
95
|
+
}, :profile_description => {
|
96
96
|
:type => lambda {
|
97
97
|
String
|
98
98
|
},
|
99
|
-
:default => :
|
99
|
+
:default => :get_default_profile_description
|
100
100
|
}, :last_loggin => {
|
101
101
|
:type => Time.now.class,
|
102
102
|
:default => lambda {
|
@@ -117,7 +117,7 @@ You can use any class, but if you need use boolean values, you must use :boolean
|
|
117
117
|
}
|
118
118
|
end
|
119
119
|
|
120
|
-
def
|
120
|
+
def get_default_profile_description
|
121
121
|
Description.where(:user_id => self.id).default
|
122
122
|
end
|
123
123
|
end
|
@@ -133,15 +133,15 @@ You can use any class, but if you need use boolean values, you must use :boolean
|
|
133
133
|
:default => 1,
|
134
134
|
:validate => lambda {
|
135
135
|
|age|
|
136
|
-
errors.add :config_age, "Are you
|
136
|
+
errors.add :config_age, "Are you Matusalen?" if age > 150
|
137
137
|
errors.add :config_age, "Are you a fetus?" if age <= 0
|
138
138
|
}
|
139
|
-
}, :
|
139
|
+
}, :profile_description => {
|
140
140
|
:type => lambda {
|
141
141
|
String
|
142
142
|
},
|
143
|
-
:default => :
|
144
|
-
:lambda => :
|
143
|
+
:default => :get_default_profile_description,
|
144
|
+
:lambda => :must_not_use_strong_language
|
145
145
|
}, :last_loggin => {
|
146
146
|
:type => Time.now.class,
|
147
147
|
:default => lambda {
|
@@ -149,7 +149,7 @@ You can use any class, but if you need use boolean values, you must use :boolean
|
|
149
149
|
},
|
150
150
|
:validate => lambda {
|
151
151
|
|time|
|
152
|
-
errors.add :config_last_loggin, "You can't loggin
|
152
|
+
errors.add :config_last_loggin, "You can't loggin on the future" if time > Time.now
|
153
153
|
}
|
154
154
|
}, :subscribe_to_rss => :get_rss_config
|
155
155
|
}
|
@@ -170,18 +170,18 @@ You can use any class, but if you need use boolean values, you must use :boolean
|
|
170
170
|
}
|
171
171
|
end
|
172
172
|
|
173
|
-
def
|
173
|
+
def get_default_profile_description
|
174
174
|
Description.where(:user_id => self.id).default
|
175
175
|
end
|
176
176
|
|
177
|
-
def
|
178
|
-
errors.add :
|
177
|
+
def must_not_use_strong_language(desc)
|
178
|
+
errors.add :cofig_profile_description, "You must not use strong language" if desc =~ /(#{STRONG_WORD.join('|')})/
|
179
179
|
end
|
180
180
|
end
|
181
181
|
|
182
182
|
### Integration in the views
|
183
183
|
|
184
|
-
If you like to use
|
184
|
+
If you like to use some configuration variable in your views you only need put the name of the input like <code>:config_name</code>, for example:
|
185
185
|
|
186
186
|
<% form_for(@user) do |f| %>
|
187
187
|
...
|
@@ -194,7 +194,7 @@ If you like to use come configuration variable in your views you only need put t
|
|
194
194
|
|
195
195
|
### Tips
|
196
196
|
|
197
|
-
If you like to do something more dynamic, like create columns and validations depending of some model or configuration,
|
197
|
+
If you like to do something more dynamic, like create columns and validations depending of some model or configuration, then you can do something like this:
|
198
198
|
|
199
199
|
class User < ActiveRecord::Base
|
200
200
|
extend_at :extra, :columns => :get_columns
|
@@ -221,7 +221,11 @@ If you like to do something more dynamic, like create columns and validations de
|
|
221
221
|
end
|
222
222
|
end
|
223
223
|
|
224
|
-
This code read the configuration of the columns when you
|
224
|
+
This code read the configuration of the columns when you access to the extra column.
|
225
|
+
|
226
|
+
## Bugs, recomendation, etc
|
227
|
+
|
228
|
+
If you found a bug, create an issue. If you have a recomendation, idea, etc., create a request or fork the project.
|
225
229
|
|
226
230
|
## License
|
227
231
|
|
data/extend_at.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.authors = ["Andrés José Borek"]
|
9
9
|
s.email = ["andres.b.dev@gmail.com"]
|
10
10
|
s.homepage = ""
|
11
|
-
s.summary = %q{Create dynamic fields
|
12
|
-
s.description = %q{This gem allows you to extend
|
11
|
+
s.summary = %q{Create dynamic fields to extend models (like content types in Drupal)}
|
12
|
+
s.description = %q{This gem allows you to extend models without migrations: This way you can, i.e., develop your own content types, like in Drupal.}
|
13
13
|
|
14
14
|
s.rubyforge_project = "extend_at"
|
15
15
|
|
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.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-01-01 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &10011740 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,9 +21,9 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
25
|
-
description: This gem allows you to extend
|
26
|
-
you can, i.e., develop your own content types, like in Drupal
|
24
|
+
version_requirements: *10011740
|
25
|
+
description: ! 'This gem allows you to extend models without migrations: This way
|
26
|
+
you can, i.e., develop your own content types, like in Drupal.'
|
27
27
|
email:
|
28
28
|
- andres.b.dev@gmail.com
|
29
29
|
executables: []
|
@@ -61,5 +61,5 @@ rubyforge_project: extend_at
|
|
61
61
|
rubygems_version: 1.8.11
|
62
62
|
signing_key:
|
63
63
|
specification_version: 3
|
64
|
-
summary: Create dynamic fields
|
64
|
+
summary: Create dynamic fields to extend models (like content types in Drupal)
|
65
65
|
test_files: []
|