README.markdown in extend_at-0.0.2 vs README.markdown in extend_at-0.0.3
- old
+ new
@@ -1,8 +1,8 @@
# Extend at
-This gem allows you to extend the columns from your model without migrations, you can, i.e., develop your own content types, like in Drupal
+This gem allows you to extend models without migrations: This way you can, i.e., develop your own content types, like in Drupal.
## Installation
<code>gem install extend_at</code>
@@ -10,15 +10,15 @@
Add in your Gemfile:
<code>gem 'extend_at'</code>
## Usage
-Only you need to add the next line in your model.
+You only need to add the next line in your model.
-<code>extend_at :configuration</code>
+<code>extend_at :extra</code>
-The column <code>configuration</code> must be string or text.
+The column <code>extra</code> must be string or text.
For example:
class User < ActiveRecord::Base
extend_at :extra
@@ -26,42 +26,42 @@
Now you can create extra attributes:
user.extra.private_photos = true
user.extra.subscribe_to_news = false
- user.extra.perfil_description = ''
+ user.extra.profile_description = ''
user.save
-Is the same:
+This is the same:
user.extra_private_photos = true
user.extra_subscribe_to_news = false
- user.extra_perfil_description = ''
+ user.extra_profile_description = ''
user.save
Or:
user[:extra_private_photos] = true
user[:extra_subscribe_to_news] = false
- user[:extra_perfil_description] = ''
+ user[:extra_profile_description] = ''
user.save
### Columns configuration
-You can configurate each column.
+You can configure each column.
#### Set column type
-You can set the type of the colum.
+You can set the colum's type.
class User < ActiveRecord::Base
extend_at :extra, :columns => {
:private_photos => {
:type => :boolean
}, :age => {
:type => :get_type
- }, :perfil_description => {
+ }, :profile_description => {
:type => lambda {
String
}
}, :last_loggin => {
:type => Time.now.class
@@ -90,15 +90,15 @@
:type => :boolean,
:default => true
}, :age => {
:type => :get_type,
:default => 1
- }, :perfil_description => {
+ }, :profile_description => {
:type => lambda {
String
},
- :default => :get_default_perfil_description
+ :default => :get_default_profile_description
}, :last_loggin => {
:type => Time.now.class,
:default => lambda {
self.created_at.time
}
@@ -115,11 +115,11 @@
:type => :boolean,
:default => true
}
end
- def get_default_perfil_description
+ def get_default_profile_description
Description.where(:user_id => self.id).default
end
end
#### Set validation
@@ -131,27 +131,27 @@
}, :age => {
:type => :get_type,
:default => 1,
:validate => lambda {
|age|
- errors.add :config_age, "Are you Matusalén?" if age > 150
+ errors.add :config_age, "Are you Matusalen?" if age > 150
errors.add :config_age, "Are you a fetus?" if age <= 0
}
- }, :perfil_description => {
+ }, :profile_description => {
:type => lambda {
String
},
- :default => :get_default_perfil_description,
- :lambda => :must_not_have_strong_language
+ :default => :get_default_profile_description,
+ :lambda => :must_not_use_strong_language
}, :last_loggin => {
:type => Time.now.class,
:default => lambda {
self.created_at.time
},
:validate => lambda {
|time|
- errors.add :config_last_loggin, "You can't loggin in the future" if time > Time.now
+ errors.add :config_last_loggin, "You can't loggin on the future" if time > Time.now
}
}, :subscribe_to_rss => :get_rss_config
}
protected
@@ -168,22 +168,22 @@
:type => :boolean,
:default => true
}
end
- def get_default_perfil_description
+ def get_default_profile_description
Description.where(:user_id => self.id).default
end
- def must_not_have_strong_language(desc)
- errors.add :cofig_perfil_description, "You must not have strong language" if desc =~ /(#{STRONG_WORD.join('|')})/
+ def must_not_use_strong_language(desc)
+ errors.add :cofig_profile_description, "You must not use strong language" if desc =~ /(#{STRONG_WORD.join('|')})/
end
end
### Integration in the views
-If you like to use come configuration variable in your views you only need put the name of the input like <code>:config_name</code>, for example:
+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:
<% form_for(@user) do |f| %>
...
<div class="field">
<%= f.label :extra_private_photos %><br />
@@ -192,11 +192,11 @@
...
<% end %>
### Tips
-If you like to do something more dynamic, like create columns and validations depending of some model or configuration, the you can do something like this:
+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:
class User < ActiveRecord::Base
extend_at :extra, :columns => :get_columns
serialize :columns_name
@@ -219,10 +219,14 @@
def get_validation(validation_type)
# ...
end
end
-This code read the configuration of the columns when you acces to extra column
+This code read the configuration of the columns when you access to the extra column.
+
+## Bugs, recomendation, etc
+
+If you found a bug, create an issue. If you have a recomendation, idea, etc., create a request or fork the project.
## License
This gem is under MIT license.
\ No newline at end of file