v_attributes 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a038eb19fe7a8e121a86727c29a3e6fdd64daa6c
4
+ data.tar.gz: 9b02f7562f0453c3b9e0c0fec5abb65d56f04dc5
5
+ SHA512:
6
+ metadata.gz: 35976b84adeb6dd0be58b3234d47c782bf3de0201eda77966ef0ddac84a0be99e0d94e50287b2f47c662de567641e308b024c4d061056ec20533873be4c19f7f
7
+ data.tar.gz: 7ffed9d0f9e3eef57f023aea9a70d2d7933451a147a55eec93e0494545af3e36a643ca704420c4eeb3a86d65dea5cd747a450138e6e75d10374a81ab2f1b3c17
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in virtual_attributes.gemspec
4
+ gemspec
@@ -0,0 +1,19 @@
1
+ desc 'virtual attributes content rake task'
2
+ task :add_virtual_attributes => :environment do
3
+ puts "Generating migration"
4
+ model_name = ENV['model'].to_s.downcase
5
+ if model_name.blank?
6
+ puts "Please provide model name."
7
+ puts "e.g rake add_virtual_attributes model=Model"
8
+ return
9
+ end
10
+ if VirtualAttributes.valid_column?(model_name)
11
+ puts "Content column alreay present in model #{model_name}"
12
+ else
13
+ `rails generate migration "add_content_to_#{ENV['model'].to_s.downcase}s" "content:text"`
14
+ puts "Running migration"
15
+ `rake db:migrate`
16
+ puts "Migration created"
17
+ end
18
+
19
+ end
@@ -0,0 +1,45 @@
1
+ require "virtual_attributes/version"
2
+ include ActiveModel::MassAssignmentSecurity
3
+
4
+ module VirtualAttributes
5
+ # Your code goes here...
6
+ require 'virtual_attributes/railtie' if defined?(Rails)
7
+ class << self
8
+ def valid_table?(model_name)
9
+ model_name.to_s.camelize.constantize
10
+ end
11
+
12
+ def valid_column?(model_name)
13
+ klass = model_name.to_s.camelize.constantize
14
+ klass.attribute_names.include?('content')
15
+ end
16
+ end
17
+
18
+ def self.included(base)
19
+ base.extend(ClassMethods)
20
+ base.serialize :content
21
+ base.after_initialize :set_content
22
+ end
23
+
24
+ module ClassMethods
25
+ def virtual_keys(*args)
26
+ args.each do |arg|
27
+ attr_accessible %(:#{arg})
28
+
29
+ define_method arg do
30
+ self.set_content
31
+ self.content[arg.to_s]
32
+ end
33
+
34
+ define_method "#{arg}=" do |new_val|
35
+ self.set_content
36
+ self.content[arg.to_s] = new_val
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ def set_content
43
+ self.content ||= {}
44
+ end
45
+ end
@@ -0,0 +1,12 @@
1
+ require 'virtual_attributes'
2
+ require 'rails'
3
+
4
+ module VirtualAttributes
5
+ class Railtie < Rails::Railtie
6
+ railtie_name :virtual_attributes
7
+
8
+ rake_tasks do
9
+ load "tasks/virtual_attributes.rake"
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module VirtualAttributes
2
+ VERSION = "0.0.2"
3
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: v_attributes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Tauqeer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Creates a field inside a model that allows you to store arbitrary n number
42
+ of attributes against a specified field.
43
+ email:
44
+ - tauqeer.ahmad2008@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - Gemfile
50
+ - lib/tasks/virtual_attributes.rake
51
+ - lib/virtual_attributes.rb
52
+ - lib/virtual_attributes/railtie.rb
53
+ - lib/virtual_attributes/version.rb
54
+ homepage: https://github.com/tauqeerahamd/virtual_attributes
55
+ licenses:
56
+ - MIT
57
+ metadata: {}
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 2.2.2
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: Creates a field inside a model that allows you to store arbitrary n number
78
+ of attributes against a specified field.
79
+ test_files: []