extend_at 0.0.1 → 0.0.2
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 +23 -3
- data/lib/extend_at/version.rb +1 -1
- data/lib/extend_at.rb +5 -4
- metadata +4 -4
data/README.markdown
CHANGED
@@ -8,7 +8,7 @@ This gem allows you to extend the columns from your model without migrations, yo
|
|
8
8
|
|
9
9
|
### Rails 3
|
10
10
|
Add in your Gemfile:
|
11
|
-
<code>gem 'extend_at'
|
11
|
+
<code>gem 'extend_at'</code>
|
12
12
|
|
13
13
|
## Usage
|
14
14
|
|
@@ -16,19 +16,35 @@ Only you need to add the next line in your model.
|
|
16
16
|
|
17
17
|
<code>extend_at :configuration</code>
|
18
18
|
|
19
|
+
The column <code>configuration</code> must be string or text.
|
20
|
+
|
19
21
|
For example:
|
20
22
|
|
21
23
|
class User < ActiveRecord::Base
|
22
24
|
extend_at :extra
|
23
25
|
end
|
24
26
|
|
25
|
-
Now you can
|
27
|
+
Now you can create extra attributes:
|
26
28
|
|
27
29
|
user.extra.private_photos = true
|
28
30
|
user.extra.subscribe_to_news = false
|
29
31
|
user.extra.perfil_description = ''
|
30
32
|
user.save
|
31
33
|
|
34
|
+
Is the same:
|
35
|
+
|
36
|
+
user.extra_private_photos = true
|
37
|
+
user.extra_subscribe_to_news = false
|
38
|
+
user.extra_perfil_description = ''
|
39
|
+
user.save
|
40
|
+
|
41
|
+
Or:
|
42
|
+
|
43
|
+
user[:extra_private_photos] = true
|
44
|
+
user[:extra_subscribe_to_news] = false
|
45
|
+
user[:extra_perfil_description] = ''
|
46
|
+
user.save
|
47
|
+
|
32
48
|
### Columns configuration
|
33
49
|
|
34
50
|
You can configurate each column.
|
@@ -205,4 +221,8 @@ If you like to do something more dynamic, like create columns and validations de
|
|
205
221
|
end
|
206
222
|
end
|
207
223
|
|
208
|
-
This code read the configuration of the columns when you acces to extra column
|
224
|
+
This code read the configuration of the columns when you acces to extra column
|
225
|
+
|
226
|
+
## License
|
227
|
+
|
228
|
+
This gem is under MIT license.
|
data/lib/extend_at/version.rb
CHANGED
data/lib/extend_at.rb
CHANGED
@@ -80,7 +80,7 @@ module ExtendModelAt
|
|
80
80
|
def assign_attributes(attributes = nil, options = {})
|
81
81
|
attributes.each_pair do |key, value|
|
82
82
|
if key.to_s =~ /^#{column_name}_/
|
83
|
-
rb = \"
|
83
|
+
rb = \"self.#{column_name}.\#\{key.to_s.gsub(/^#{column_name}_/,'')\} = value\"
|
84
84
|
eval rb, binding
|
85
85
|
end
|
86
86
|
end
|
@@ -93,7 +93,7 @@ module ExtendModelAt
|
|
93
93
|
# Return the value of <<attributes>> methods like <column name>_<extended column name>
|
94
94
|
def [](column)
|
95
95
|
if column.to_s =~ /^#{column_name}_[a-zA-Z_][a-zA-Z_0-9]*\=?$/
|
96
|
-
rb = \"
|
96
|
+
rb = \"self.#{column_name}.\#\{column.to_s.gsub(/^#{column_name}_/,'').gsub(/\=$/, '')\}\"
|
97
97
|
eval rb, binding
|
98
98
|
else
|
99
99
|
super
|
@@ -103,7 +103,8 @@ module ExtendModelAt
|
|
103
103
|
# Write the value of <<attributes>> methods like <column name>_<extended column name>
|
104
104
|
def []=(column, value)
|
105
105
|
if column.to_s =~ /^#{column_name}_[a-zA-Z_][a-zA-Z_0-9]*\=?$/
|
106
|
-
rb = \"
|
106
|
+
rb = \"self.#{column_name}.\#\{column.to_s.gsub(/^#{column_name}_/,'').gsub(/\=$/, '')\} = value\"
|
107
|
+
puts \"Evaluando: #\{rb}\"
|
107
108
|
eval rb, binding
|
108
109
|
else
|
109
110
|
super
|
@@ -122,7 +123,7 @@ module ExtendModelAt
|
|
122
123
|
# Accept method like <column name>_<extended column name> for read or write
|
123
124
|
def method_missing(m, *args, &block)
|
124
125
|
if m.to_s =~ /^#{column_name}_[a-zA-Z_][a-zA-Z_0-9]*\=$/
|
125
|
-
rb = \"self.#{column_name}.\#\{m.to_s.gsub(/^#{column_name}_/, '')} = args.first\"
|
126
|
+
rb = \"self.#{column_name}.\#\{m.to_s.gsub(/^#{column_name}_/, '').gsub(/\=$/, '')} = args.first\"
|
126
127
|
return eval rb, binding
|
127
128
|
elsif m.to_s =~ /^#{column_name}_[a-zA-Z_][a-zA-Z_0-9]*$/
|
128
129
|
rb = \"self.#{column_name}.\#\{m.to_s.gsub(/^#{column_name}_/, '')}\"
|
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.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
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: &13710780 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *13710780
|
25
25
|
description: This gem allows you to extend the columns from your model without migrations,
|
26
26
|
you can, i.e., develop your own content types, like in Drupal
|
27
27
|
email:
|