vattributes 0.0.1

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.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +23 -0
  5. data/Gemfile +14 -0
  6. data/Gemfile.lock +121 -0
  7. data/MIT-LICENSE +20 -0
  8. data/README.md +70 -0
  9. data/Rakefile +21 -0
  10. data/lib/tasks/vattributes_tasks.rake +4 -0
  11. data/lib/vattributes.rb +6 -0
  12. data/lib/vattributes/extension.rb +44 -0
  13. data/lib/vattributes/version.rb +3 -0
  14. data/spec/dummy/README.rdoc +28 -0
  15. data/spec/dummy/Rakefile +6 -0
  16. data/spec/dummy/app/assets/images/.keep +0 -0
  17. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  18. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  19. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  20. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  21. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  22. data/spec/dummy/app/mailers/.keep +0 -0
  23. data/spec/dummy/app/models/.keep +0 -0
  24. data/spec/dummy/app/models/concerns/.keep +0 -0
  25. data/spec/dummy/app/models/user.rb +3 -0
  26. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  27. data/spec/dummy/bin/bundle +3 -0
  28. data/spec/dummy/bin/rails +4 -0
  29. data/spec/dummy/bin/rake +4 -0
  30. data/spec/dummy/config.ru +4 -0
  31. data/spec/dummy/config/application.rb +28 -0
  32. data/spec/dummy/config/boot.rb +5 -0
  33. data/spec/dummy/config/database.yml +25 -0
  34. data/spec/dummy/config/environment.rb +5 -0
  35. data/spec/dummy/config/environments/development.rb +29 -0
  36. data/spec/dummy/config/environments/production.rb +80 -0
  37. data/spec/dummy/config/environments/test.rb +36 -0
  38. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  39. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  40. data/spec/dummy/config/initializers/inflections.rb +16 -0
  41. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  42. data/spec/dummy/config/initializers/secret_token.rb +12 -0
  43. data/spec/dummy/config/initializers/session_store.rb +3 -0
  44. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  45. data/spec/dummy/config/locales/en.yml +23 -0
  46. data/spec/dummy/config/routes.rb +56 -0
  47. data/spec/dummy/db/migrate/20140307225710_create_users.rb +10 -0
  48. data/spec/dummy/db/schema.rb +23 -0
  49. data/spec/dummy/lib/assets/.keep +0 -0
  50. data/spec/dummy/log/.keep +0 -0
  51. data/spec/dummy/public/404.html +58 -0
  52. data/spec/dummy/public/422.html +58 -0
  53. data/spec/dummy/public/500.html +57 -0
  54. data/spec/dummy/public/favicon.ico +0 -0
  55. data/spec/dummy/spec/models/user_spec.rb +5 -0
  56. data/spec/spec_helper.rb +31 -0
  57. data/spec/vattributes/extension_spec.rb +45 -0
  58. data/vattributes.gemspec +27 -0
  59. metadata +221 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a0a43e00a8fd8b7dd1feb992549630319ae8d2e1
4
+ data.tar.gz: 7696da92cdc5bc04d45fc1c4f387d0afb631461b
5
+ SHA512:
6
+ metadata.gz: e2b73a745b37bea741314814bd5265655745954f17d4091426247e316727da97003ce60c23735cdca143abaf474fb4ffe7c10821e2bf2f230f7923cfd0928fc9
7
+ data.tar.gz: a67567ae02ca5ae6a372263cd24f433f4f30a57bc9e8b5f7d9b002fe9764a42e36e01db4bc53a6cd58aa5203f82b46858a5ba4ccb74ee8d696d884bae91c7119
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ spec/dummy/db/*.sqlite3
5
+ spec/dummy/db/*.sqlite3-journal
6
+ spec/dummy/log/*.log
7
+ spec/dummy/tmp/
8
+ spec/dummy/.sass-cache
9
+ coverage
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,23 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ env:
5
+ - DB=sqlite
6
+ - DB=mysql
7
+ - DB=postgresql
8
+ script:
9
+ - RAILS_ENV=test bundle exec rake db:migrate --trace
10
+ - TRAVIS=true bundle exec rspec spec/
11
+ gemfile:
12
+ # - gemfiles/Gemfile.rails-3.2.x
13
+ - Gemfile
14
+ before_script:
15
+ - cd spec/dummy
16
+ - mysql -e 'create database vattributes_test'
17
+ - psql -c 'create database vattributes_test' -U postgres
18
+ notifications:
19
+ email:
20
+ on_failure: change
21
+ branches:
22
+ only:
23
+ - master
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Declare your gem's dependencies in vattributes.gemspec.
4
+ # Bundler will treat runtime dependencies like base dependencies, and
5
+ # development dependencies will be added by default to the :development group.
6
+ gemspec
7
+
8
+ # Declare any dependencies that are still in development here instead of in
9
+ # your gemspec. These might include edge Rails or gems from your path or
10
+ # Git. Remember to move these dependencies to your gemspec before releasing
11
+ # your gem to rubygems.org.
12
+
13
+ # To use debugger
14
+ # gem 'debugger'
data/Gemfile.lock ADDED
@@ -0,0 +1,121 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ vattributes (0.0.1)
5
+ rails (>= 3.0, <= 5.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actionmailer (4.0.3)
11
+ actionpack (= 4.0.3)
12
+ mail (~> 2.5.4)
13
+ actionpack (4.0.3)
14
+ activesupport (= 4.0.3)
15
+ builder (~> 3.1.0)
16
+ erubis (~> 2.7.0)
17
+ rack (~> 1.5.2)
18
+ rack-test (~> 0.6.2)
19
+ activemodel (4.0.3)
20
+ activesupport (= 4.0.3)
21
+ builder (~> 3.1.0)
22
+ activerecord (4.0.3)
23
+ activemodel (= 4.0.3)
24
+ activerecord-deprecated_finders (~> 1.0.2)
25
+ activesupport (= 4.0.3)
26
+ arel (~> 4.0.0)
27
+ activerecord-deprecated_finders (1.0.3)
28
+ activesupport (4.0.3)
29
+ i18n (~> 0.6, >= 0.6.4)
30
+ minitest (~> 4.2)
31
+ multi_json (~> 1.3)
32
+ thread_safe (~> 0.1)
33
+ tzinfo (~> 0.3.37)
34
+ arel (4.0.2)
35
+ atomic (1.1.15)
36
+ builder (3.1.4)
37
+ coveralls (0.7.0)
38
+ multi_json (~> 1.3)
39
+ rest-client
40
+ simplecov (>= 0.7)
41
+ term-ansicolor
42
+ thor
43
+ diff-lcs (1.2.5)
44
+ docile (1.1.1)
45
+ erubis (2.7.0)
46
+ hike (1.2.3)
47
+ i18n (0.6.9)
48
+ mail (2.5.4)
49
+ mime-types (~> 1.16)
50
+ treetop (~> 1.4.8)
51
+ mime-types (1.25.1)
52
+ minitest (4.7.5)
53
+ multi_json (1.9.0)
54
+ polyglot (0.3.4)
55
+ rack (1.5.2)
56
+ rack-test (0.6.2)
57
+ rack (>= 1.0)
58
+ rails (4.0.3)
59
+ actionmailer (= 4.0.3)
60
+ actionpack (= 4.0.3)
61
+ activerecord (= 4.0.3)
62
+ activesupport (= 4.0.3)
63
+ bundler (>= 1.3.0, < 2.0)
64
+ railties (= 4.0.3)
65
+ sprockets-rails (~> 2.0.0)
66
+ railties (4.0.3)
67
+ actionpack (= 4.0.3)
68
+ activesupport (= 4.0.3)
69
+ rake (>= 0.8.7)
70
+ thor (>= 0.18.1, < 2.0)
71
+ rake (10.1.1)
72
+ rest-client (1.6.7)
73
+ mime-types (>= 1.16)
74
+ rspec-core (2.14.8)
75
+ rspec-expectations (2.14.5)
76
+ diff-lcs (>= 1.1.3, < 2.0)
77
+ rspec-mocks (2.14.6)
78
+ rspec-rails (2.14.1)
79
+ actionpack (>= 3.0)
80
+ activemodel (>= 3.0)
81
+ activesupport (>= 3.0)
82
+ railties (>= 3.0)
83
+ rspec-core (~> 2.14.0)
84
+ rspec-expectations (~> 2.14.0)
85
+ rspec-mocks (~> 2.14.0)
86
+ simplecov (0.8.2)
87
+ docile (~> 1.1.0)
88
+ multi_json
89
+ simplecov-html (~> 0.8.0)
90
+ simplecov-html (0.8.0)
91
+ sprockets (2.11.0)
92
+ hike (~> 1.2)
93
+ multi_json (~> 1.0)
94
+ rack (~> 1.0)
95
+ tilt (~> 1.1, != 1.3.0)
96
+ sprockets-rails (2.0.1)
97
+ actionpack (>= 3.0)
98
+ activesupport (>= 3.0)
99
+ sprockets (~> 2.8)
100
+ sqlite3 (1.3.9)
101
+ term-ansicolor (1.2.2)
102
+ tins (~> 0.8)
103
+ thor (0.18.1)
104
+ thread_safe (0.2.0)
105
+ atomic (>= 1.1.7, < 2)
106
+ tilt (1.4.1)
107
+ tins (0.13.1)
108
+ treetop (1.4.15)
109
+ polyglot
110
+ polyglot (>= 0.3.1)
111
+ tzinfo (0.3.38)
112
+
113
+ PLATFORMS
114
+ ruby
115
+
116
+ DEPENDENCIES
117
+ coveralls
118
+ rspec-rails
119
+ simplecov
120
+ sqlite3
121
+ vattributes!
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # V(irtual)attributes
2
+
3
+ Makes virtual attributes easier.
4
+
5
+ [![Build Status](https://travis-ci.org/mjacobus/vattributes.png?branch=master)](https://travis-ci.org/mjacobus/vattributes)
6
+ [![Coverage Status](https://coveralls.io/repos/mjacobus/vattributes/badge.png)](https://coveralls.io/r/mjacobus/vattributes)
7
+ [![Code Climate](https://codeclimate.com/github/mjacobus/vattributes.png)](https://codeclimate.com/github/mjacobus/vattributes)
8
+ [![Dependency Status](https://gemnasium.com/mjacobus/vattributes.png)](https://gemnasium.com/mjacobus/vattributes)
9
+ [![Gem Version](https://badge.fury.io/rb/vattributes.png)](http://badge.fury.io/rb/vattributes)
10
+
11
+ ## Instalation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'vattributes'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ ```bash
22
+ $ bundle
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ Add the vattributes field to the table as a text and run the migration:
28
+
29
+ ```bash
30
+ rails g migration AddVattributesToPosts vattributes:text
31
+ rake db:migrate
32
+ ```
33
+
34
+ ```ruby
35
+ class Post < ActiveRecord::Base
36
+ vattributes :permalink
37
+
38
+ validates :permalink, presence: true
39
+ end
40
+ ```
41
+
42
+ If you ever need to overrite a setter, or getter, you can do like follows:
43
+
44
+ ```ruby
45
+ class Post < ActiveRecord::Base
46
+ vattributes :tags, :permalink
47
+
48
+ def tags=(array)
49
+ set_vattribute(:tags, array.join(','))
50
+ end
51
+
52
+ def tags
53
+ get_vattribute(:tags).split(',')
54
+ end
55
+ end
56
+ ```
57
+
58
+ ## Authors
59
+
60
+ - [Marcelo Jacobus](https://github.com/mjacobus)
61
+
62
+ ## Contributing
63
+
64
+ 1. Fork it
65
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
66
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
67
+ 4. Push to the branch (`git push origin my-new-feature`)
68
+ 5. Create new Pull Request
69
+
70
+ ** Do not forget to write tests**
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Vattributes'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+ Bundler::GemHelper.install_tasks
21
+
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :vattributes do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,6 @@
1
+ require 'active_support/concern'
2
+ require 'vattributes/extension'
3
+
4
+ module Vattributes
5
+ end
6
+
@@ -0,0 +1,44 @@
1
+ module Vattributes
2
+ module Extension
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ serialize :vattributes, JSON
7
+ end
8
+
9
+ def vattribute_get(name)
10
+ self.virtual_attributes[name.to_s]
11
+ end
12
+
13
+ def vattribute_set(name, value)
14
+ self.vattributes = self.virtual_attributes.merge({ name.to_s => value })
15
+ end
16
+
17
+ def virtual_attributes
18
+ read_attribute(:vattributes) || {}
19
+ end
20
+
21
+ module ClassMethods
22
+ def vattributes(*names)
23
+ names.each do |name|
24
+
25
+ # setter
26
+ define_method "#{name}=" do |value|
27
+ vattribute_set(name, value)
28
+ end
29
+
30
+ # getter
31
+ define_method "#{name}" do
32
+ vattribute_get(name)
33
+ end
34
+
35
+ end
36
+ end
37
+ end
38
+
39
+ end
40
+ end
41
+
42
+ if defined?(ActiveRecord)
43
+ ActiveRecord::Base.send(:include, Vattributes::Extension)
44
+ end
@@ -0,0 +1,3 @@
1
+ module Vattributes
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Dummy::Application.load_tasks
File without changes
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end