Class: ActiveRecord::Generators::PayGenerator

Inherits:
Base
  • Object
show all
Includes:
Pay::Generators::OrmHelpers
Defined in:
lib/generators/active_record/pay_generator.rb

Instance Method Summary collapse

Methods included from Pay::Generators::OrmHelpers

#model_contents

Instance Method Details

#copy_pay_billable_migrationObject



12
13
14
15
16
17
# File 'lib/generators/active_record/pay_generator.rb', line 12

def copy_pay_billable_migration
  if (behavior == :invoke && model_exists?) || (behavior == :revoke && migration_exists?(table_name))
    migration_template "migration.rb", "#{migration_path}/add_pay_billable_to_#{table_name}.rb", migration_version: migration_version
  end
  # TODO: Throw error here that model should already exist if it doesn't
end

#inject_pay_billable_contentObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/generators/active_record/pay_generator.rb', line 19

def inject_pay_billable_content
  content = model_contents

  class_path = if namespaced?
    class_name.to_s.split("::")
  else
    [class_name]
  end

  indent_depth = class_path.size - 1
  content = content.split("\n").map { |line| "  " * indent_depth + line }.join("\n") << "\n"

  inject_into_class(model_path, class_path.last, content) if model_exists?
end

#migration_dataObject



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/generators/active_record/pay_generator.rb', line 34

def migration_data
  <<RUBY
t.string :processor
t.string :processor_id
t.datetime :trial_ends_at
t.string :card_type
t.string :card_last4
t.string :card_exp_month
t.string :card_exp_year
t.text :extra_billing_info
RUBY
end

#migration_versionObject



51
52
53
54
55
# File 'lib/generators/active_record/pay_generator.rb', line 51

def migration_version
  if rails5_and_up?
    "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
  end
end

#rails5_and_up?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/generators/active_record/pay_generator.rb', line 47

def rails5_and_up?
  Rails::VERSION::MAJOR >= 5
end