has_dynamic_fields 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +62 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +63 -0
- data/Rakefile +67 -0
- data/VERSION +1 -0
- data/lib/generators/dynamic_field_migration_generator.rb +79 -0
- data/lib/generators/dynamic_field_scaffold_generator.rb +148 -0
- data/lib/generators/templates/add_field_migration.rb +5 -0
- data/lib/generators/templates/fieldgroup_model_template.rb +3 -0
- data/lib/generators/templates/fieldgroups_table_migration.rb +11 -0
- data/lib/generators/templates/fieldoptions_model_template.rb +3 -0
- data/lib/generators/templates/fieldoptions_table_migration.rb +23 -0
- data/lib/generators/templates/fields_model_template.rb +3 -0
- data/lib/generators/templates/fields_table_migration.rb +24 -0
- data/lib/generators/templates/fieldvalues_model_template.rb +4 -0
- data/lib/generators/templates/fieldvalues_table_migration.rb +19 -0
- data/lib/generators/templates/remove_field_migration.rb +5 -0
- data/lib/tasks/dynamic_field_migrate.rake +7 -0
- data/spec/spec_helper.rb +12 -0
- data/test/helper.rb +18 -0
- metadata +181 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
gem "seed-fu"
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "rspec", "~> 2.8.0"
|
10
|
+
gem "shoulda", ">= 0"
|
11
|
+
gem "rdoc", "~> 3.12"
|
12
|
+
gem "bundler", "~> 1.0.0"
|
13
|
+
gem "jeweler", "~> 1.8.3"
|
14
|
+
gem "simplecov", ">= 0"
|
15
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activemodel (3.2.3)
|
5
|
+
activesupport (= 3.2.3)
|
6
|
+
builder (~> 3.0.0)
|
7
|
+
activerecord (3.2.3)
|
8
|
+
activemodel (= 3.2.3)
|
9
|
+
activesupport (= 3.2.3)
|
10
|
+
arel (~> 3.0.2)
|
11
|
+
tzinfo (~> 0.3.29)
|
12
|
+
activesupport (3.2.3)
|
13
|
+
i18n (~> 0.6)
|
14
|
+
multi_json (~> 1.0)
|
15
|
+
arel (3.0.2)
|
16
|
+
builder (3.0.0)
|
17
|
+
diff-lcs (1.1.3)
|
18
|
+
git (1.2.5)
|
19
|
+
i18n (0.6.0)
|
20
|
+
jeweler (1.8.3)
|
21
|
+
bundler (~> 1.0)
|
22
|
+
git (>= 1.2.5)
|
23
|
+
rake
|
24
|
+
rdoc
|
25
|
+
json (1.6.6)
|
26
|
+
multi_json (1.2.0)
|
27
|
+
rake (0.9.2.2)
|
28
|
+
rdoc (3.12)
|
29
|
+
json (~> 1.4)
|
30
|
+
rspec (2.8.0)
|
31
|
+
rspec-core (~> 2.8.0)
|
32
|
+
rspec-expectations (~> 2.8.0)
|
33
|
+
rspec-mocks (~> 2.8.0)
|
34
|
+
rspec-core (2.8.0)
|
35
|
+
rspec-expectations (2.8.0)
|
36
|
+
diff-lcs (~> 1.1.2)
|
37
|
+
rspec-mocks (2.8.0)
|
38
|
+
seed-fu (2.2.0)
|
39
|
+
activerecord (~> 3.1)
|
40
|
+
activesupport (~> 3.1)
|
41
|
+
shoulda (3.0.1)
|
42
|
+
shoulda-context (~> 1.0.0)
|
43
|
+
shoulda-matchers (~> 1.0.0)
|
44
|
+
shoulda-context (1.0.0)
|
45
|
+
shoulda-matchers (1.0.0)
|
46
|
+
simplecov (0.6.1)
|
47
|
+
multi_json (~> 1.0)
|
48
|
+
simplecov-html (~> 0.5.3)
|
49
|
+
simplecov-html (0.5.3)
|
50
|
+
tzinfo (0.3.32)
|
51
|
+
|
52
|
+
PLATFORMS
|
53
|
+
ruby
|
54
|
+
|
55
|
+
DEPENDENCIES
|
56
|
+
bundler (~> 1.0.0)
|
57
|
+
jeweler (~> 1.8.3)
|
58
|
+
rdoc (~> 3.12)
|
59
|
+
rspec (~> 2.8.0)
|
60
|
+
seed-fu
|
61
|
+
shoulda
|
62
|
+
simplecov
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Jason Ayre
|
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.rdoc
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
= has_dynamic_fields
|
2
|
+
|
3
|
+
Turns your models into dynamic models, in a non traditional EAV style.
|
4
|
+
|
5
|
+
Normal EAV would have a values table, that looks like:
|
6
|
+
|
7
|
+
id entity_id attribute_id value_id
|
8
|
+
|
9
|
+
Acts as dynamics value table looks like this
|
10
|
+
|
11
|
+
id entity_id field_1 field_2 field_3 field_4 field_5
|
12
|
+
|
13
|
+
With a fields table that looks like
|
14
|
+
|
15
|
+
id name label bunchofoptions
|
16
|
+
|
17
|
+
The ID of this field, corresponds to column in value table, for that particular lookup. So its more of a matrix style EAV.
|
18
|
+
Field columns are dynamically added to Fields table as they are created. (not yet)
|
19
|
+
|
20
|
+
---
|
21
|
+
|
22
|
+
## Scaffold Generator
|
23
|
+
|
24
|
+
The options are fairly verbose, I apologize in advance, I wanted to give the maximum amount of flexibility when working with this gem.
|
25
|
+
|
26
|
+
#### Examples
|
27
|
+
|
28
|
+
rails g dynamic_field_scaffold post use_fieldgroup_table:true create_fieldgroup_table:true fieldgroup_table_name:post_categories
|
29
|
+
|
30
|
+
Where "post" above, is the name of the entity you are creating the fields for. It should be an existing model in your app, this is the only model the generator won't create.
|
31
|
+
|
32
|
+
The command above should generate output similar to these files:
|
33
|
+
|
34
|
+
create db/migrate/20120416191442_create_post_fields.rb
|
35
|
+
create db/migrate/20120416191443_create_post_field_values.rb
|
36
|
+
create db/migrate/20120416191444_create_post_field_options.rb
|
37
|
+
create db/migrate/20120416191445_create_post_categories.rb
|
38
|
+
create app/models/post_field.rb
|
39
|
+
create app/models/post_field_value.rb
|
40
|
+
create app/models/post_field_option.rb
|
41
|
+
create app/models/post_category.rb
|
42
|
+
|
43
|
+
Post category here is acting as the fieldgroup, scoping the available fields for a given post, by category.
|
44
|
+
This allows you to have different sets of fields for different categories of entities.
|
45
|
+
In order to utilize this behavior, you obviously need to first have a user choose a post category, when creating a post, so that they are then able to see the scoped fields.
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
== Contributing to acts_as_dynamic
|
50
|
+
|
51
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
52
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
53
|
+
* Fork the project.
|
54
|
+
* Start a feature/bugfix branch.
|
55
|
+
* Commit and push until you are happy with your contribution.
|
56
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
57
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
58
|
+
|
59
|
+
== Copyright
|
60
|
+
|
61
|
+
Copyright (c) 2012 Jason Ayre. See LICENSE.txt for
|
62
|
+
further details.
|
63
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "has_dynamic_fields"
|
18
|
+
gem.homepage = "http://github.com/jasonayre/has_dynamic_fields"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = "Lets your models act dynamically in a clean EAV style"
|
21
|
+
gem.description = "Lets your models act dynamic in a clean EAV style"
|
22
|
+
gem.email = "jasonayre@gmail.com"
|
23
|
+
gem.authors = ["Jason Ayre"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
require 'rspec/core'
|
36
|
+
require 'rspec/core/rake_task'
|
37
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
38
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
39
|
+
spec.rspec_opts = ["--color"]
|
40
|
+
end
|
41
|
+
|
42
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
43
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
44
|
+
spec.rcov = true
|
45
|
+
end
|
46
|
+
|
47
|
+
task :default => :spec
|
48
|
+
|
49
|
+
# require 'simplecov/simplecovtask'
|
50
|
+
# Simplecov::SimplecovTask.new do |test|
|
51
|
+
# test.libs << 'test'
|
52
|
+
# test.pattern = 'test/**/test_*.rb'
|
53
|
+
# test.verbose = true
|
54
|
+
# test.simplecov_opts << '--exclude "gems/*"'
|
55
|
+
# end
|
56
|
+
|
57
|
+
# task :default => :test
|
58
|
+
|
59
|
+
require 'rdoc/task'
|
60
|
+
Rake::RDocTask.new do |rdoc|
|
61
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
62
|
+
|
63
|
+
rdoc.rdoc_dir = 'rdoc'
|
64
|
+
rdoc.title = "acts_as_dynamic #{version}"
|
65
|
+
rdoc.rdoc_files.include('README*')
|
66
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
67
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'rails/generators/active_record/migration'
|
2
|
+
class DynamicFieldMigrationGenerator < Rails::Generators::Base
|
3
|
+
|
4
|
+
include Rails::Generators::Migration
|
5
|
+
# extend ActiveRecord::Generators::Migration
|
6
|
+
argument :migration_name, :type => :string
|
7
|
+
argument :arguments, :type => :hash
|
8
|
+
|
9
|
+
source_root File.expand_path('../templates', __FILE__)
|
10
|
+
|
11
|
+
def generate_migration
|
12
|
+
destination = "db/migrate/dynamic_fields/#{next_migration_number}_#{file_name}.rb"
|
13
|
+
|
14
|
+
@migration_file_name = File.basename(destination).sub(".rb", "").split("_").slice(1..100).join('_')
|
15
|
+
|
16
|
+
@migration_class_name = @migration_file_name.camelize
|
17
|
+
|
18
|
+
migration_already_exists = self.class.migration_exists?("db/migrate/dynamic_fields/", @migration_file_name)
|
19
|
+
template "#{migration_type}_field_migration.rb", destination unless self.class.migration_exists?("db/migrate/dynamic_fields/", @migration_file_name)
|
20
|
+
`rake db:migrate_dynamic_fields` unless migration_already_exists
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def file_name
|
27
|
+
migration_name.underscore
|
28
|
+
end
|
29
|
+
|
30
|
+
def migration_type
|
31
|
+
file_name.split("_").first
|
32
|
+
end
|
33
|
+
|
34
|
+
def migration_verb
|
35
|
+
if migration_type == "add"
|
36
|
+
return "to"
|
37
|
+
elsif migration_type == "remove"
|
38
|
+
return "from"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def table_name
|
43
|
+
migration_name.sub("#{migration_type}_", "").split("_#{migration_verb}_").last
|
44
|
+
end
|
45
|
+
|
46
|
+
def field_id
|
47
|
+
migration_name.sub("#{migration_type}_field_", "").split("_#{migration_verb}_").first
|
48
|
+
end
|
49
|
+
|
50
|
+
def column_name
|
51
|
+
migration_name.sub("#{migration_type}_", "").split("_#{migration_verb}_").first
|
52
|
+
end
|
53
|
+
|
54
|
+
def column_type
|
55
|
+
arguments[column_name].to_sym
|
56
|
+
end
|
57
|
+
|
58
|
+
def migration_klass_name
|
59
|
+
file_name.classify.pluralize
|
60
|
+
end
|
61
|
+
|
62
|
+
def next_migration_number
|
63
|
+
if ActiveRecord::Base.timestamped_migrations
|
64
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
65
|
+
else
|
66
|
+
"%.3d" % (current_migration_number("db/migrate") + 1)
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
def data_table_name
|
72
|
+
table_name.sub("_data", "")
|
73
|
+
end
|
74
|
+
|
75
|
+
def field_entity
|
76
|
+
data_table_name.classify.constantize.find(field_id)
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
require 'rails/generators/active_record/migration'
|
2
|
+
class DynamicFieldScaffoldGenerator < Rails::Generators::Base
|
3
|
+
|
4
|
+
include Rails::Generators::Migration
|
5
|
+
# extend ActiveRecord::Generators::Migration
|
6
|
+
argument :table_name, :type => :string
|
7
|
+
argument :arguments, :type => :hash
|
8
|
+
|
9
|
+
source_root File.expand_path('../templates', __FILE__)
|
10
|
+
|
11
|
+
def generate_migration
|
12
|
+
|
13
|
+
template "fields_table_migration.rb", "db/migrate/#{next_migration_number(Time.now)}_create_#{fields_table_name}.rb"
|
14
|
+
template "fieldvalues_table_migration.rb", "db/migrate/#{next_migration_number(Time.now+1)}_create_#{fieldvalues_table_name}.rb"
|
15
|
+
|
16
|
+
if use_fieldoptions_table
|
17
|
+
template "fieldoptions_table_migration.rb", "db/migrate/#{next_migration_number(Time.now+2)}_create_#{fieldoptions_table_name}.rb"
|
18
|
+
end
|
19
|
+
|
20
|
+
if create_fieldgroup_table
|
21
|
+
template "fieldgroups_table_migration.rb", "db/migrate/#{next_migration_number(Time.now+3)}_create_#{fieldgroup_table_name}.rb"
|
22
|
+
end
|
23
|
+
|
24
|
+
if create_models
|
25
|
+
template "fields_model_template.rb", "app/models/#{fields_model_name.tableize.singularize}.rb"
|
26
|
+
template "fieldvalues_model_template.rb", "app/models/#{fieldvalues_model_name.tableize.singularize}.rb"
|
27
|
+
if use_fieldoptions_table
|
28
|
+
template "fieldoptions_model_template.rb", "app/models/#{fieldoptions_model_name.tableize.singularize}.rb"
|
29
|
+
end
|
30
|
+
if use_fieldgroup_table
|
31
|
+
template "fieldgroup_model_template.rb", "app/models/#{fieldgroup_model_name.tableize.singularize}.rb"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def create_models
|
40
|
+
if arguments["create_models"].present?
|
41
|
+
arguments["create_models"]
|
42
|
+
else
|
43
|
+
return true
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def use_fieldgroup_table
|
48
|
+
arguments["use_fieldgroup_table"]
|
49
|
+
end
|
50
|
+
|
51
|
+
def fieldgroup_table_name
|
52
|
+
arguments["fieldgroup_table_name"]
|
53
|
+
end
|
54
|
+
|
55
|
+
def fieldgroup_klass_name
|
56
|
+
arguments["fieldgroup_table_name"].singularize.classify
|
57
|
+
end
|
58
|
+
|
59
|
+
def create_fieldgroup_table
|
60
|
+
if use_fieldgroup_table
|
61
|
+
if arguments["create_fieldgroup_table"].present?
|
62
|
+
return arguments["create_fieldgroup_table"]
|
63
|
+
else
|
64
|
+
return true
|
65
|
+
end
|
66
|
+
else
|
67
|
+
return false
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def fieldgroup_foreign_key
|
72
|
+
"#{arguments["fieldgroup_table_name"].singularize}_id"
|
73
|
+
end
|
74
|
+
|
75
|
+
def use_fieldoptions_table
|
76
|
+
if arguments["use_fieldoptions_table"].present?
|
77
|
+
return arguments["use_fieldoptions_table"]
|
78
|
+
else
|
79
|
+
return true
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def fieldoptions_table_name
|
84
|
+
if arguments["fieldoptions_table_name"].present?
|
85
|
+
arguments["fieldoptions_table_name"]
|
86
|
+
else
|
87
|
+
"#{table_name.underscore}_field_options"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def fieldoptions_klass_name
|
92
|
+
fieldoptions_table_name.singularize.classify
|
93
|
+
end
|
94
|
+
|
95
|
+
def entity_klass_name
|
96
|
+
table_name.classify.singularize
|
97
|
+
end
|
98
|
+
|
99
|
+
def entity_table_name
|
100
|
+
entity_klass_name.underscore.pluralize
|
101
|
+
end
|
102
|
+
|
103
|
+
def entity_foreign_key
|
104
|
+
"#{entity_table_name.singularize}_id"
|
105
|
+
end
|
106
|
+
|
107
|
+
def fields_table_name
|
108
|
+
"#{table_name.underscore}_fields"
|
109
|
+
end
|
110
|
+
|
111
|
+
def fields_klass_name
|
112
|
+
fields_table_name.classify.pluralize
|
113
|
+
end
|
114
|
+
|
115
|
+
def fieldvalues_table_name
|
116
|
+
"#{table_name.underscore}_field_values"
|
117
|
+
end
|
118
|
+
|
119
|
+
def fieldvalues_klass_name
|
120
|
+
fieldvalues_table_name.classify.singularize
|
121
|
+
end
|
122
|
+
|
123
|
+
def fields_model_name
|
124
|
+
fields_table_name.classify.singularize
|
125
|
+
end
|
126
|
+
|
127
|
+
def fieldvalues_model_name
|
128
|
+
fieldvalues_table_name.classify.singularize
|
129
|
+
end
|
130
|
+
|
131
|
+
def fieldoptions_model_name
|
132
|
+
fieldoptions_table_name.classify.singularize
|
133
|
+
end
|
134
|
+
|
135
|
+
def fieldgroup_model_name
|
136
|
+
fieldgroup_table_name.classify.singularize
|
137
|
+
end
|
138
|
+
|
139
|
+
def next_migration_number(time)
|
140
|
+
# @migration_count ||= 0
|
141
|
+
if ActiveRecord::Base.timestamped_migrations
|
142
|
+
time.utc.strftime("%Y%m%d%H%M%S")
|
143
|
+
else
|
144
|
+
"%.3d" % (current_migration_number("db/migrate") + 1)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class Create<%= fieldgroup_klass_name.pluralize %> < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :<%= fieldgroup_table_name %> do |t|
|
4
|
+
t.string :name
|
5
|
+
t.timestamps
|
6
|
+
end
|
7
|
+
change_table :<%= fieldgroup_table_name %> do |t|
|
8
|
+
t.index :name
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Create<%= fieldoptions_klass_name.pluralize %> < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :<%= fieldoptions_table_name %> do |t|
|
4
|
+
t.string :label
|
5
|
+
t.string :value
|
6
|
+
t.integer :sort_order
|
7
|
+
t.string :heading_text
|
8
|
+
t.string :description
|
9
|
+
t.string :image
|
10
|
+
<% if use_fieldgroup_table %>
|
11
|
+
t.integer :<%= fieldgroup_foreign_key %>
|
12
|
+
<% end %>
|
13
|
+
t.timestamps
|
14
|
+
end
|
15
|
+
|
16
|
+
change_table :<%= fieldoptions_table_name %> do |t|
|
17
|
+
<% if use_fieldgroup_table %>
|
18
|
+
t.index :<%= fieldgroup_foreign_key %>
|
19
|
+
<% end %>
|
20
|
+
t.index :label
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class Create<%= fields_klass_name.pluralize %> < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :<%= fields_table_name %> do |t|
|
4
|
+
<% if use_fieldgroup_table %>
|
5
|
+
t.integer :<%= fieldgroup_foreign_key %>
|
6
|
+
<% end %>
|
7
|
+
t.string :name
|
8
|
+
t.string :label
|
9
|
+
t.string :placeholder
|
10
|
+
t.string :fieldtype
|
11
|
+
t.integer :sort_order
|
12
|
+
t.string :button_text
|
13
|
+
t.string :validation_method
|
14
|
+
end
|
15
|
+
change_table :<%= fields_table_name %> do |t|
|
16
|
+
<% if use_fieldgroup_table %>
|
17
|
+
t.index :<%= fieldgroup_foreign_key %>
|
18
|
+
<% end %>
|
19
|
+
t.index :name
|
20
|
+
t.index :label
|
21
|
+
t.index :fieldtype
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class Create<%= fieldvalues_klass_name.pluralize %> < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :<%= fieldvalues_table_name %> do |t|
|
4
|
+
t.integer :<%= entity_foreign_key %>
|
5
|
+
<% if use_fieldgroup_table %>
|
6
|
+
t.integer :<%= fieldgroup_foreign_key %>
|
7
|
+
<% end %>
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
|
11
|
+
change_table :<%= fieldvalues_table_name %> do |t|
|
12
|
+
t.index :<%= entity_foreign_key %>
|
13
|
+
<% if use_fieldgroup_table %>
|
14
|
+
t.index :<%= fieldgroup_foreign_key %>
|
15
|
+
<% end %>
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
namespace :db do
|
2
|
+
task :migrate_dynamic_fields => :environment do
|
3
|
+
ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
|
4
|
+
ActiveRecord::Migrator.migrate("db/migrate/dynamic_fields", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
|
5
|
+
Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
|
6
|
+
end
|
7
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'has_dynamic_fields'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'acts_as_dynamic'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: has_dynamic_fields
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jason Ayre
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: seed-fu
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.8.0
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.8.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: shoulda
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rdoc
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '3.12'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '3.12'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: bundler
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 1.0.0
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 1.0.0
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: jeweler
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 1.8.3
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 1.8.3
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: simplecov
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
description: Lets your models act dynamic in a clean EAV style
|
127
|
+
email: jasonayre@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files:
|
131
|
+
- LICENSE.txt
|
132
|
+
- README.rdoc
|
133
|
+
files:
|
134
|
+
- .document
|
135
|
+
- Gemfile
|
136
|
+
- Gemfile.lock
|
137
|
+
- LICENSE.txt
|
138
|
+
- README.rdoc
|
139
|
+
- Rakefile
|
140
|
+
- VERSION
|
141
|
+
- lib/generators/dynamic_field_migration_generator.rb
|
142
|
+
- lib/generators/dynamic_field_scaffold_generator.rb
|
143
|
+
- lib/generators/templates/add_field_migration.rb
|
144
|
+
- lib/generators/templates/fieldgroup_model_template.rb
|
145
|
+
- lib/generators/templates/fieldgroups_table_migration.rb
|
146
|
+
- lib/generators/templates/fieldoptions_model_template.rb
|
147
|
+
- lib/generators/templates/fieldoptions_table_migration.rb
|
148
|
+
- lib/generators/templates/fields_model_template.rb
|
149
|
+
- lib/generators/templates/fields_table_migration.rb
|
150
|
+
- lib/generators/templates/fieldvalues_model_template.rb
|
151
|
+
- lib/generators/templates/fieldvalues_table_migration.rb
|
152
|
+
- lib/generators/templates/remove_field_migration.rb
|
153
|
+
- lib/tasks/dynamic_field_migrate.rake
|
154
|
+
- spec/spec_helper.rb
|
155
|
+
- test/helper.rb
|
156
|
+
homepage: http://github.com/jasonayre/has_dynamic_fields
|
157
|
+
licenses:
|
158
|
+
- MIT
|
159
|
+
post_install_message:
|
160
|
+
rdoc_options: []
|
161
|
+
require_paths:
|
162
|
+
- lib
|
163
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
164
|
+
none: false
|
165
|
+
requirements:
|
166
|
+
- - ! '>='
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '0'
|
169
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
170
|
+
none: false
|
171
|
+
requirements:
|
172
|
+
- - ! '>='
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: '0'
|
175
|
+
requirements: []
|
176
|
+
rubyforge_project:
|
177
|
+
rubygems_version: 1.8.22
|
178
|
+
signing_key:
|
179
|
+
specification_version: 3
|
180
|
+
summary: Lets your models act dynamically in a clean EAV style
|
181
|
+
test_files: []
|