Class: Milia::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/milia/install_generator.rb

Overview

*************************************************************

Instance Method Summary collapse

Instance Method Details

#check_requirementsObject




21
22
23
# File 'lib/generators/milia/install_generator.rb', line 21

def check_requirements()
  gem_find_or_fail( %w(devise) )
end

#initialize_template_variablesObject




27
28
29
30
31
# File 'lib/generators/milia/install_generator.rb', line 27

def initialize_template_variables()
  @skip_recaptcha = options.skip_recaptcha
  @skip_invite_member = options.skip_invite_member
  @use_airbrake = options.use_airbrake
end

#setup_deviseObject




55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/generators/milia/install_generator.rb', line 55

def setup_devise
  unless options.skip_devise_generators
    generate "devise:install"
    generate "devise", "user"
  end
  gsub_file "app/models/user.rb", /,\s*$/, ", :confirmable,"

  migrate_user_file = find_or_fail("db/migrate/[0-9]*_devise_create_users.rb")

  uncomment_lines( migrate_user_file, /confirm/ )
  inject_into_file migrate_user_file, after: "# t.datetime :locked_at\n" do
    snippet_db_migrate_user
  end

  gsub_file 'config/initializers/devise.rb', /config.mailer_sender = '.+'/, "config.mailer_sender = '#{options.org_email}'"

end

#setup_environmentsObject




153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/generators/milia/install_generator.rb', line 153

def setup_environments

  unless options.skip_env_email_setup

    environment nil, env: :development do
      snippet_env_dev
    end  # do dev environment

    environment nil, env: :production do
      snippet_env_prod
    end  # do production environment

    environment nil, env: :test do
      snippet_env_test
    end  # do test environment

    environment  do
      snippet_config_application
    end  # do config_application

  end
end

#setup_initial_stuffObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/generators/milia/install_generator.rb', line 37

def setup_initial_stuff
  copy_file 'devise_permitted_parameters.rb', 'config/initializers/devise_permitted_parameters.rb'
  template 'initializer.rb', 'config/initializers/milia.rb'

   unless options.skip_recaptcha
     gem 'recaptcha', :require => "recaptcha/rails"
   end
   if options.use_airbrake
     gem 'airbrake'
   end

   gem 'activerecord-session_store', github: 'rails/activerecord-session_store'

   run_bundle
end

#setup_miliaObject




75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/generators/milia/install_generator.rb', line 75

def setup_milia

  unless false    # future skip block??
    inject_into_file "app/controllers/application_controller.rb",
                     after: "protect_from_forgery with: :exception\n" do
      snippet_app_ctlr_header
    end

    route  snippet_routes_root_path

    generate "controller", "home index"
    generate "active_record:session_migration"
    generate "model", "tenant tenant:references name:string:index"
    generate "migration", "CreateTenantsUsersJoinTable tenants users"

    inject_into_class "app/controllers/home_controller.rb", HomeController do
       snippet_home_ctlr_header
    end

    join_file = find_or_fail("db/migrate/[0-9]*_create_tenants_users_join_table.rb")
    uncomment_lines join_file, ":tenant_id, :user_id"

    gsub_file "config/routes.rb", "devise_for :users"  do
      snippet_routes_devise
    end

    inject_into_file "app/models/user.rb",
      after: ":recoverable, :rememberable, :trackable, :validatable\n" do
      
    end

    gsub_file "app/models/tenant.rb", /belongs_to \:tenant/, ' '

    inject_into_class "app/models/tenant.rb", Tenant do
       snippet_model_tenant_determines_tenant
    end

  end  # skip block?
end

#setup_milia_memberObject


115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/generators/milia/install_generator.rb', line 115

def setup_milia_member

  unless options.skip_invite_member

    generate "resource", "member tenant:references user:references first_name:string last_name:string"

    inject_into_file "app/models/tenant.rb",
      after: "acts_as_universal_and_determines_tenant\n" do
         snippet_add_assoc_to_tenant
    end

    uncomment_lines "app/models/tenant.rb", "create_org_admin"

    inject_into_file "app/models/user.rb",
      after: "acts_as_universal_and_determines_account\n" do
        snippet_add_member_assoc_to_user
    end

    gsub_file "app/models/member.rb", /belongs_to \:tenant/, ' '

    inject_into_file "app/models/member.rb",
      after: "belongs_to :user\n" do
       snippet_fill_out_member
    end

    inject_into_class "app/controllers/members_controller.rb", MembersController do
       snippet_fill_member_ctlr
    end

    directory File.expand_path('../../../../app/views/members', __FILE__), "app/views/members"
    directory File.expand_path('../../../../app/views/devise/registrations', __FILE__), "app/views/devise/registrations"


  end  # skip any member expansion
end

#wrapupObject




179
180
181
182
183
184
185
186
187
# File 'lib/generators/milia/install_generator.rb', line 179

def wrapup()
  alert_color = :red
  say("-------------------------------------------------------------------------", alert_color)
  say("-   milia installation complete", alert_color)
  say("-   please edit your email, domain, password in config/environments/*", alert_color)
  say("-   please edit devise config/initializers/devise.rb", alert_color)
  say("-   please run migrations: $ rake db:migrate", alert_color)
  say("-------------------------------------------------------------------------", alert_color)
end