Class: Connect::ModelsGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Connect::ModelsGenerator
- Defined in:
- lib/generators/connect/models_generator.rb
Instance Method Summary collapse
- #create_account ⇒ Object
- #create_contact ⇒ Object
- #create_contract ⇒ Object
- #directory ⇒ Object
- #modname ⇒ Object
Instance Method Details
#create_account ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/generators/connect/models_generator.rb', line 9 def create_account create_file "#{directory}/account.rb", " module \#{modname}\nclass Account < ApplicationRecord\n require 'connect/record'\n include Connect::Record\n self.table_name = \"salesforce.account\"\n\n has_many :salesforce_contacts, class_name: \"\#{modname}::Contact\",\n foreign_key: :accountid, primary_key: :sfid, dependent: :nullify\n\n has_one :salesforce_contract, class_name: \"\#{modname}::Contract\",\n foreign_key: :accountid, primary_key: :sfid, dependent: :nullify\nend\n end\n FILE\nend\n" |
#create_contact ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/generators/connect/models_generator.rb', line 27 def create_contact create_file "#{directory}/contact.rb", " module \#{modname}\nclass Contact < ApplicationRecord\n require 'connect/record'\n include Connect::Record\n self.table_name = \"salesforce.contact\"\n\n validates :email, presence: true, uniqueness: true\n\n belongs_to :salesforce_account, class_name: \"Salesforce::Account\",\n primary_key: :sfid, foreign_key: :accountid, optional: true\nend\n end\n FILE\nend\n" |
#create_contract ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/generators/connect/models_generator.rb', line 44 def create_contract create_file "#{directory}/contract.rb", " module \#{modname}\nclass Contract < ApplicationRecord\n require 'connect/record'\n include Connect::Record\n self.table_name = \"salesforce.contract\"\n\n belongs_to :salesforce_account, class_name: \"Salesforce::Account\",\n primary_key: :sfid, foreign_key: :accountid\nend\n end\n FILE\nend\n" |
#directory ⇒ Object
63 64 65 |
# File 'lib/generators/connect/models_generator.rb', line 63 def directory "app/models/#{modname.underscore}" end |
#modname ⇒ Object
59 60 61 |
# File 'lib/generators/connect/models_generator.rb', line 59 def modname ['module'] end |