Class: Tellimus::InstallGenerator

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_pathsObject



12
13
14
# File 'lib/generators/tellimus/install_generator.rb', line 12

def self.source_paths
  [Tellimus::Engine.root, File.expand_path("../templates", __FILE__)]
end

Instance Method Details

#installObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/generators/tellimus/install_generator.rb', line 28

def install

  unless defined?(Tellimus)
    gem("tellimus")
  end

  require "securerandom"
  template "config/initializers/tellimus.rb"

  # Generate subscription.
  generate("model", "subscription braintree_id:string braintree_customer_id:string plan_id:integer payment_signature:string payment_type:string current_price:float #{subscription_owner_model}_id:integer")
  template "app/models/subscription.rb"

  # Add the plans.
  generate("model", "plan name:string braintree_id:string price:float interval:string features:text highlight:boolean display_order:integer")
  template "app/models/plan.rb"

  # Update the owner relationship.
  inject_into_class "app/models/#{subscription_owner_model}.rb", subscription_owner_model.camelize.constantize,
                    "# Added by Tellimus.\n  has_one :subscription\n\n"

  # Install the pricing table.
  copy_file "app/views/tellimus/subscriptions/_social_proof.html.erb"

  # Add webhooks to the route.

  route <<-RUBY

  # Added by Tellimus.
  mount Tellimus::Engine, at: 'tellimus'
  scope module: 'tellimus' do
get 'pricing' => 'subscriptions#index', as: 'pricing'
  end

RUBY
end

#subscription_owner_modelObject

Override the attr_accessor generated by ‘argument’ so that subscription_owner_model is always returned lowercase.



23
24
25
# File 'lib/generators/tellimus/install_generator.rb', line 23

def subscription_owner_model
  @subscription_owner_model ? @subscription_owner_model.downcase : "user"
end