survey_generator 0.2.93 → 0.2.94

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ODM1ZmU1NTJmMTllMjZjZWY4MzRjYzIwN2U0OWQyNGUzYjllNGVjNw==
4
+ ZDFlMDNjMmYwZDJjMThlOWIyZmFiNjg2MmE4NTEwMjc1OGM1MWQ2Mg==
5
5
  data.tar.gz: !binary |-
6
- YmJhMjA2ZWE0ODE5ZmRkOTJkMGI4Y2NmNzQ5MjRhNjM1Yjk1ZDZjMQ==
6
+ NTFmZmMxYmFlZjFlZDAzYzM0NzhiNWYwNTU4MDRhNTZjMjE0ODJiMw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZjQ0ODNmNzgwZTdiYTczYzVjMjA0YzgxMjY4N2ZhNmIyN2IyODVjNWU5ZjJm
10
- Mjg1ZTc5MjA3OTU5YzkxNDY5Mzg3ZjIxYzlhMmEwMGMwOTA2MTI3OWUxNzE2
11
- ZjFhM2I1Yjk0YjU5Zjk1MTQ4MzkxYmNkMjg4YWRlOTdlY2EyM2Q=
9
+ ZWVkMDQ1Yjc3OTI3MjM2YWQzZTVmMGQ5NGUwNGFjNjc0NWMyZDg2MjAzMmI1
10
+ ZTg1NjIzMjE3NmZlMDQyMmViYjgxNzdlNDEyYzYyMDhkZmZmMTIzY2M5ZTQy
11
+ YTJhYTk0MWY1MDI4ZjIwNGJiNTc0NWVkM2YzZjE5NzVhZTFlM2Q=
12
12
  data.tar.gz: !binary |-
13
- OGU5NWM0ZmI4ZWNhYzE3MjA3NDUyZjA0ZjY4Njk4OTNhNTcxNzBhYTc4OTRm
14
- NDdhZDdhMmVmZWE4ZDgwNjdhZDNhZDI1MDhhYTUwYmZjMGVjOTNmYTY5NDA0
15
- ZmE3OGQwNGU2OGYxMjNjODhkNmJlYjlhYTMyNTQ3ZDVhMTZmODU=
13
+ YWU2MDVjOTVkNjcyNWZmNTg3NWUzOTBjOTY3YTkwN2YyYzc2ZTE2YTRjNzVi
14
+ ZjU3MWI5MDNlNjEyZjM1YjIzN2YzMDA0OTU3NWQxYTAwMzE3YzAyNDU2ZTVk
15
+ ZjY0N2ExYWVlNmE4N2E1NTA2MzdiYTg3ZmUxYzk4ZjE5ZThlYTI=
@@ -2,10 +2,4 @@ Description:
2
2
  This generator will generate classes for a rails application to display a survey.
3
3
 
4
4
  Example:
5
- rails generate survey
6
-
7
- This will create:
8
- app/controllers/[NAME]_controller.rb
9
- app/models/[NAME].rb
10
- app/views/[NAME]/_form.html.erb
11
- app/views/[NAME]/index.html.erb
5
+ rails generate survey
@@ -1,16 +1,128 @@
1
1
  $:.unshift File.dirname(__FILE__)
2
2
 
3
- require 'metamodels/survey_metamodel'
4
- require 'rgen/template_language'
5
- require 'rgen/array_extensions'
6
-
7
3
  class SurveyGenerator < Rails::Generators::Base
8
- source_root File.expand_path('/templates', __FILE__)
4
+ argument :model_path, :type => :string, :default => "#{Rails.root.to_s}/gen/models/survey_model"
5
+ class_option :init, :type => :boolean, :default => false, :desc => "Performs all actions."
6
+ class_option :gems, :type => :boolean, :default => false, :desc => "Initialize application."
7
+ class_option :migrate, :type => :boolean, :default => false, :desc => "Perform database migrations."
8
+ class_option :populate, :type => :boolean, :default => false, :desc => "Populate database with users."
9
9
 
10
10
  def generate_survey
11
- require Rails.root.to_s + '/gen/models/survey_model'
12
- tc = RGen::TemplateLanguage::DirectoryTemplateContainer.new(SurveyMetamodel, Rails.root.to_s)
13
- tc.load(File.dirname(__FILE__) + '/templates')
14
- tc.expand('main::root', for: MODEL.first)
11
+ init_gems if options.gems? or options.init?
12
+
13
+ if File.exists? "#{model_path}.rb"
14
+ require model_path
15
+
16
+ if !(defined?(MODEL)).nil? && !MODEL.first.nil?
17
+ puts "Generating ruby on rails source code for the defined survey."
18
+
19
+ require 'metamodels/survey_metamodel'
20
+ require 'rgen/template_language'
21
+ require 'rgen/array_extensions'
22
+
23
+ tc = RGen::TemplateLanguage::DirectoryTemplateContainer.new(SurveyMetamodel, Rails.root.to_s)
24
+ tc.load(File.dirname(__FILE__) + '/templates')
25
+ tc.expand('main::root', for: MODEL.first)
26
+
27
+ migrate if options.migrate? or options.init?
28
+ populate if options.populate? or options.init?
29
+ else
30
+ puts "Model is empty. Please define a survey first."
31
+ end
32
+ else
33
+ puts "Model file does not exist."
34
+ create_model_file
35
+ end
15
36
  end
37
+
38
+ private
39
+
40
+ def init_gems
41
+ puts " initializing application"
42
+
43
+ #init_gemfile
44
+
45
+ #For all environments
46
+ #gem 'rails', '3.2.13'
47
+ gem 'bootstrap-sass', '2.1'
48
+ gem 'bcrypt-ruby', '3.0.1'
49
+ gem 'faker', '1.0.1'
50
+ gem 'will_paginate', '3.0.3'
51
+ gem 'bootstrap-will_paginate', '0.0.6'
52
+ #gem 'jquery-rails'
53
+ gem 'rgen'
54
+ gem 'survey_generator'
55
+
56
+ #Group 'development' and 'test'
57
+ gem_group :development, :test do
58
+ #gem 'sqlite3'
59
+ gem 'rspec-rails', '2.11.0'
60
+ end
61
+
62
+ #Group 'test'
63
+ gem_group :test do
64
+ gem 'capybara', '1.1.2'
65
+ gem 'factory_girl_rails', '4.1.0'
66
+ gem 'cucumber-rails', '1.2.1', :require => false
67
+ gem 'database_cleaner', '0.7.0'
68
+ end
69
+
70
+ #Group 'production'
71
+ gem_group :production do
72
+ gem 'pg', '0.12.2'
73
+ end
74
+
75
+ #gem_group :assets do
76
+ # gem 'sass-rails','~> 3.2.3'
77
+ # gem 'coffee-rails', '~> 3.2.1'
78
+ # gem 'uglifier', '>= 1.0.3'
79
+ #end
80
+
81
+ if File.exists? "#{Rails.root.to_s}/public/index.html"
82
+ run "rm public/index.html"
83
+ end
84
+
85
+ run "bundle install"
86
+ end
87
+
88
+ def init_gemfile
89
+ remove_file "Gemfile"
90
+ create_file "Gemfile", <<-RUBY
91
+ source 'https://rubygems.org'
92
+ RUBY
93
+ end
94
+
95
+ def create_model_file
96
+ puts "\t creating model file"
97
+
98
+ create_file "gen/models/survey_model.rb", <<-RUBY
99
+ require 'rgen/model_builder'
100
+ require 'metamodels/survey_metamodel'
101
+
102
+ MODEL = RGen::ModelBuilder.build(SurveyMetamodel) {}
103
+ RUBY
104
+ end
105
+
106
+ def migrate
107
+ puts "\t performing database migrations"
108
+
109
+ rake "db:reset"
110
+ rake "db:migrate"
111
+ end
112
+
113
+ def populate
114
+ puts "\t populating database with users"
115
+
116
+ admin = User.create!(name: "Example User", email: "example@railstutorial.org", password: "foobar", password_confirmation: "foobar")
117
+ admin.toggle!(:admin)
118
+ admin2 = User.create!(name: "Daniel Kemper", email: "dkemp04@gmail.com", password: "foobar", password_confirmation: "foobar")
119
+ admin2.toggle!(:admin)
120
+
121
+ 99.times do |n|
122
+ name = Faker::Name.name
123
+ email = "example-#{n + 1}@railstutorial.org"
124
+ password = "password"
125
+ User.create!(name: name, email: email, password: password, password_confirmation: password)
126
+ end
127
+ end
16
128
  end
@@ -1,6 +1,6 @@
1
1
  <% define 'routes', for: Survey do %>
2
2
  <% file "config/routes.rb" do %>
3
- Generator::Application.routes.draw do<%iinc%>
3
+ <%= Rails.application.class.parent_name %>::Application.routes.draw do<%iinc%>
4
4
  resources :<%= name.pluralize.downcase %>
5
5
  resources :users
6
6
  resources :sessions, only: [:new, :create, :destroy]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: survey_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.93
4
+ version: 0.2.94
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dkemp04
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-14 00:00:00.000000000 Z
11
+ date: 2013-05-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A generator for surveys based on model-driven development with RGen.
14
14
  email: dkemp04@gmail.com
@@ -67,8 +67,6 @@ files:
67
67
  - lib/generators/survey/templates/db/migrate/create_users.tpl
68
68
  - lib/generators/survey/templates/main.tpl
69
69
  - lib/generators/survey/USAGE
70
- - lib/tasks/my_plugin.rake
71
- - lib/tasks/survey_generator.rake
72
70
  homepage: http://rubygems.org/gems/survey_generator
73
71
  licenses: []
74
72
  metadata: {}
@@ -1,4 +0,0 @@
1
- desc 'my plugins rake task'
2
- task :do_something do
3
- puts "the rake task did something"
4
- end
@@ -1,14 +0,0 @@
1
- desc "Fill database with sample data"
2
- task :prepare do
3
- admin = User.create!(name: "Example User", email: "example@railstutorial.org", password: "foobar", password_confirmation: "foobar")
4
- admin.toggle!(:admin)
5
- admin2 = User.create!(name: "Daniel Kemper", email: "dkemp04@gmail.com", password: "foobar", password_confirmation: "foobar")
6
- admin2.toggle!(:admin)
7
-
8
- 99.times do |n|
9
- name = Faker::Name.name
10
- email = "example-#{n + 1}@railstutorial.org"
11
- password = "password"
12
- User.create!(name: name, email: email, password: password, password_confirmation: password)
13
- end
14
- end