{"action":"created","comment":{"url":"https://api.github.com/repos/tablexi/restforce-db/pulls/comments/33222542","id":33222542,"diff_hunk":"@@ -1,6 +1,102 @@\n #!/usr/bin/env ruby\n \n-require File.expand_path(File.join(File.dirname(__FILE__), \"..\", \"config\", \"environment\"))\n-require \"restforce/db/command\"\n+if ARGV[0] != \"meta\"\n+  require File.expand_path(File.join(File.dirname(__FILE__), \"..\", \"config\", \"environment\"))\n+  require \"restforce/db/command\"\n \n-Restforce::DB::Command.new(ARGV).daemonize\n+  Restforce::DB::Command.new(ARGV).daemonize\n+elsif ARGV.length > 1 && !defined?(Bundler)\n+\n+  # MetadataInitializer exposes functionality to automatically add an\n+  # external Synchronization ID to your Salesforce models.\n+  class MetadataInitializer\n+\n+    # Public: Initialize a new MetadataInitializer.\n+    #\n+    # config_file - The path to a configuration file.\n+    # models      - An Array of String Salesforce model names.\n+    def initialize(config_file, *models)\n+      @models = models\n+      @config = YAML.load_file(config_file)\n+    end\n+\n+    # Public: Set up an external Synchronization ID for each specified\n+    # Salesforce model.\n+    #\n+    # Returns nothing.\n+    def setup\n+      @models.each do |model|\n+        print \"ADDING SynchronizationId__c to #{model}... \"\n+        job = client.create(\n+          :custom_field,\n+          full_name: \"#{model}.SynchronizationId__c\",\n+          description: \"External Synchronization ID\",\n+          label: \"Synchronization ID\",\n+          type: \"Text\",\n+          external_id: true,\n+          unique: true,\n+          length: ENV[\"UUID_LENGTH\"] || 255,\n+        )\n+\n+        begin\n+          job.on_complete { |_| puts \"DONE\" }.on_error { |_| puts \"FAILED\" }.perform\n+        rescue Savon::SOAP::Fault => e\n+          puts \"\\n(#{e.class}) #{e.message}\\n#{e.backtrace.join(\"\\n\")}\"\n+        end\n+      end\n+    end\n+\n+    # Internal: Get a Metaforce client to process the custom field CRUD\n+    # requests.\n+    #\n+    # Returns a Metaforce::Metadata:Client.\n+    def client\n+      @client ||= begin\n+        Metaforce.configure do |configuration|\n+          configuration.host = @config[\"client\"][\"host\"]\n+          configuration.log = false\n+        end\n+\n+        options = {\n+          username: @config[\"client\"][\"username\"],\n+          password: @config[\"client\"][\"password\"],\n+          security_token: @config[\"client\"][\"security_token\"],\n+        }\n+\n+        # Verify the login credentials\n+        Metaforce.login(options)\n+        Metaforce.new(options)\n+      end\n+    end\n+\n+  end\n+\n+  # Suppress bundler output\n+  require \"stringio\"\n+  stdout, $stdout = $stdout, StringIO.new\n+\n+  # NOTE: For whatever reason, bundler/inline's \"install\" functionality seems\n+  # busted. We can work around it by just installing the gem ourselves, as a\n+  # convenience to users.\n+  `gem install metaforce`","path":"lib/generators/templates/script","position":null,"original_position":84,"commit_id":"da7889772aa4ca7592846b5c785c50e78afa34cb","original_commit_id":"cdb2421aebb46816683c658c6080ed33b212ef54","user":{"login":"ahorner","id":116396,"avatar_url":"https://avatars.githubusercontent.com/u/116396?v=3","gravatar_id":"","url":"https://api.github.com/users/ahorner","html_url":"https://github.com/ahorner","followers_url":"https://api.github.com/users/ahorner/followers","following_url":"https://api.github.com/users/ahorner/following{/other_user}","gists_url":"https://api.github.com/users/ahorner/gists{/gist_id}","starred_url":"https://api.github.com/users/ahorner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahorner/subscriptions","organizations_url":"https://api.github.com/users/ahorner/orgs","repos_url":"https://api.github.com/users/ahorner/repos","events_url":"https://api.github.com/users/ahorner/events{/privacy}","received_events_url":"https://api.github.com/users/ahorner/received_events","type":"User","site_admin":false},"body":"I went for an alternate approach, and simply exposed the output from the gem installation when the script can tell it needs to install `metaforce`. This should give users enough information to uninstall any gems they don't want around. Let me know what you think.","created_at":"2015-06-25T05:00:21Z","updated_at":"2015-06-25T05:00:21Z","html_url":"https://github.com/tablexi/restforce-db/pull/48#discussion_r33222542","pull_request_url":"https://api.github.com/repos/tablexi/restforce-db/pulls/48","_links":{"self":{"href":"https://api.github.com/repos/tablexi/restforce-db/pulls/comments/33222542"},"html":{"href":"https://github.com/tablexi/restforce-db/pull/48#discussion_r33222542"},"pull_request":{"href":"https://api.github.com/repos/tablexi/restforce-db/pulls/48"}}},"pull_request":{"url":"https://api.github.com/repos/tablexi/restforce-db/pulls/48","id":38498451,"html_url":"https://github.com/tablexi/restforce-db/pull/48","diff_url":"https://github.com/tablexi/restforce-db/pull/48.diff","patch_url":"https://github.com/tablexi/restforce-db/pull/48.patch","issue_url":"https://api.github.com/repos/tablexi/restforce-db/issues/48","number":48,"state":"open","locked":false,"title":"Use `#upsert!` mechanism to create new records","user":{"login":"ahorner","id":116396,"avatar_url":"https://avatars.githubusercontent.com/u/116396?v=3","gravatar_id":"","url":"https://api.github.com/users/ahorner","html_url":"https://github.com/ahorner","followers_url":"https://api.github.com/users/ahorner/followers","following_url":"https://api.github.com/users/ahorner/following{/other_user}","gists_url":"https://api.github.com/users/ahorner/gists{/gist_id}","starred_url":"https://api.github.com/users/ahorner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahorner/subscriptions","organizations_url":"https://api.github.com/users/ahorner/orgs","repos_url":"https://api.github.com/users/ahorner/repos","events_url":"https://api.github.com/users/ahorner/events{/privacy}","received_events_url":"https://api.github.com/users/ahorner/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-06-24T23:25:32Z","updated_at":"2015-06-25T05:00:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ae98306e81f50e8b9ab56fa5d85b85ce0f0ba713","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/tablexi/restforce-db/pulls/48/commits","review_comments_url":"https://api.github.com/repos/tablexi/restforce-db/pulls/48/comments","review_comment_url":"https://api.github.com/repos/tablexi/restforce-db/pulls/comments{/number}","comments_url":"https://api.github.com/repos/tablexi/restforce-db/issues/48/comments","statuses_url":"https://api.github.com/repos/tablexi/restforce-db/statuses/da7889772aa4ca7592846b5c785c50e78afa34cb","head":{"label":"tablexi:upsert_new_records","ref":"upsert_new_records","sha":"da7889772aa4ca7592846b5c785c50e78afa34cb","user":{"login":"tablexi","id":229702,"avatar_url":"https://avatars.githubusercontent.com/u/229702?v=3","gravatar_id":"","url":"https://api.github.com/users/tablexi","html_url":"https://github.com/tablexi","followers_url":"https://api.github.com/users/tablexi/followers","following_url":"https://api.github.com/users/tablexi/following{/other_user}","gists_url":"https://api.github.com/users/tablexi/gists{/gist_id}","starred_url":"https://api.github.com/users/tablexi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tablexi/subscriptions","organizations_url":"https://api.github.com/users/tablexi/orgs","repos_url":"https://api.github.com/users/tablexi/repos","events_url":"https://api.github.com/users/tablexi/events{/privacy}","received_events_url":"https://api.github.com/users/tablexi/received_events","type":"Organization","site_admin":false},"repo":{"id":32425520,"name":"restforce-db","full_name":"tablexi/restforce-db","owner":{"login":"tablexi","id":229702,"avatar_url":"https://avatars.githubusercontent.com/u/229702?v=3","gravatar_id":"","url":"https://api.github.com/users/tablexi","html_url":"https://github.com/tablexi","followers_url":"https://api.github.com/users/tablexi/followers","following_url":"https://api.github.com/users/tablexi/following{/other_user}","gists_url":"https://api.github.com/users/tablexi/gists{/gist_id}","starred_url":"https://api.github.com/users/tablexi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tablexi/subscriptions","organizations_url":"https://api.github.com/users/tablexi/orgs","repos_url":"https://api.github.com/users/tablexi/repos","events_url":"https://api.github.com/users/tablexi/events{/privacy}","received_events_url":"https://api.github.com/users/tablexi/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/tablexi/restforce-db","description":"Bind your database to Salesforce data","fork":false,"url":"https://api.github.com/repos/tablexi/restforce-db","forks_url":"https://api.github.com/repos/tablexi/restforce-db/forks","keys_url":"https://api.github.com/repos/tablexi/restforce-db/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tablexi/restforce-db/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tablexi/restforce-db/teams","hooks_url":"https://api.github.com/repos/tablexi/restforce-db/hooks","issue_events_url":"https://api.github.com/repos/tablexi/restforce-db/issues/events{/number}","events_url":"https://api.github.com/repos/tablexi/restforce-db/events","assignees_url":"https://api.github.com/repos/tablexi/restforce-db/assignees{/user}","branches_url":"https://api.github.com/repos/tablexi/restforce-db/branches{/branch}","tags_url":"https://api.github.com/repos/tablexi/restforce-db/tags","blobs_url":"https://api.github.com/repos/tablexi/restforce-db/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tablexi/restforce-db/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tablexi/restforce-db/git/refs{/sha}","trees_url":"https://api.github.com/repos/tablexi/restforce-db/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tablexi/restforce-db/statuses/{sha}","languages_url":"https://api.github.com/repos/tablexi/restforce-db/languages","stargazers_url":"https://api.github.com/repos/tablexi/restforce-db/stargazers","contributors_url":"https://api.github.com/repos/tablexi/restforce-db/contributors","subscribers_url":"https://api.github.com/repos/tablexi/restforce-db/subscribers","subscription_url":"https://api.github.com/repos/tablexi/restforce-db/subscription","commits_url":"https://api.github.com/repos/tablexi/restforce-db/commits{/sha}","git_commits_url":"https://api.github.com/repos/tablexi/restforce-db/git/commits{/sha}","comments_url":"https://api.github.com/repos/tablexi/restforce-db/comments{/number}","issue_comment_url":"https://api.github.com/repos/tablexi/restforce-db/issues/comments{/number}","contents_url":"https://api.github.com/repos/tablexi/restforce-db/contents/{+path}","compare_url":"https://api.github.com/repos/tablexi/restforce-db/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tablexi/restforce-db/merges","archive_url":"https://api.github.com/repos/tablexi/restforce-db/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tablexi/restforce-db/downloads","issues_url":"https://api.github.com/repos/tablexi/restforce-db/issues{/number}","pulls_url":"https://api.github.com/repos/tablexi/restforce-db/pulls{/number}","milestones_url":"https://api.github.com/repos/tablexi/restforce-db/milestones{/number}","notifications_url":"https://api.github.com/repos/tablexi/restforce-db/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tablexi/restforce-db/labels{/name}","releases_url":"https://api.github.com/repos/tablexi/restforce-db/releases{/id}","created_at":"2015-03-17T23:04:27Z","updated_at":"2015-05-07T21:05:06Z","pushed_at":"2015-06-25T04:58:34Z","git_url":"git://github.com/tablexi/restforce-db.git","ssh_url":"git@github.com:tablexi/restforce-db.git","clone_url":"https://github.com/tablexi/restforce-db.git","svn_url":"https://github.com/tablexi/restforce-db","homepage":null,"size":1646,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"tablexi:master","ref":"master","sha":"9f4a82fdd7587903d1281e7ebb461db1088da195","user":{"login":"tablexi","id":229702,"avatar_url":"https://avatars.githubusercontent.com/u/229702?v=3","gravatar_id":"","url":"https://api.github.com/users/tablexi","html_url":"https://github.com/tablexi","followers_url":"https://api.github.com/users/tablexi/followers","following_url":"https://api.github.com/users/tablexi/following{/other_user}","gists_url":"https://api.github.com/users/tablexi/gists{/gist_id}","starred_url":"https://api.github.com/users/tablexi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tablexi/subscriptions","organizations_url":"https://api.github.com/users/tablexi/orgs","repos_url":"https://api.github.com/users/tablexi/repos","events_url":"https://api.github.com/users/tablexi/events{/privacy}","received_events_url":"https://api.github.com/users/tablexi/received_events","type":"Organization","site_admin":false},"repo":{"id":32425520,"name":"restforce-db","full_name":"tablexi/restforce-db","owner":{"login":"tablexi","id":229702,"avatar_url":"https://avatars.githubusercontent.com/u/229702?v=3","gravatar_id":"","url":"https://api.github.com/users/tablexi","html_url":"https://github.com/tablexi","followers_url":"https://api.github.com/users/tablexi/followers","following_url":"https://api.github.com/users/tablexi/following{/other_user}","gists_url":"https://api.github.com/users/tablexi/gists{/gist_id}","starred_url":"https://api.github.com/users/tablexi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tablexi/subscriptions","organizations_url":"https://api.github.com/users/tablexi/orgs","repos_url":"https://api.github.com/users/tablexi/repos","events_url":"https://api.github.com/users/tablexi/events{/privacy}","received_events_url":"https://api.github.com/users/tablexi/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/tablexi/restforce-db","description":"Bind your database to Salesforce data","fork":false,"url":"https://api.github.com/repos/tablexi/restforce-db","forks_url":"https://api.github.com/repos/tablexi/restforce-db/forks","keys_url":"https://api.github.com/repos/tablexi/restforce-db/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tablexi/restforce-db/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tablexi/restforce-db/teams","hooks_url":"https://api.github.com/repos/tablexi/restforce-db/hooks","issue_events_url":"https://api.github.com/repos/tablexi/restforce-db/issues/events{/number}","events_url":"https://api.github.com/repos/tablexi/restforce-db/events","assignees_url":"https://api.github.com/repos/tablexi/restforce-db/assignees{/user}","branches_url":"https://api.github.com/repos/tablexi/restforce-db/branches{/branch}","tags_url":"https://api.github.com/repos/tablexi/restforce-db/tags","blobs_url":"https://api.github.com/repos/tablexi/restforce-db/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tablexi/restforce-db/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tablexi/restforce-db/git/refs{/sha}","trees_url":"https://api.github.com/repos/tablexi/restforce-db/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tablexi/restforce-db/statuses/{sha}","languages_url":"https://api.github.com/repos/tablexi/restforce-db/languages","stargazers_url":"https://api.github.com/repos/tablexi/restforce-db/stargazers","contributors_url":"https://api.github.com/repos/tablexi/restforce-db/contributors","subscribers_url":"https://api.github.com/repos/tablexi/restforce-db/subscribers","subscription_url":"https://api.github.com/repos/tablexi/restforce-db/subscription","commits_url":"https://api.github.com/repos/tablexi/restforce-db/commits{/sha}","git_commits_url":"https://api.github.com/repos/tablexi/restforce-db/git/commits{/sha}","comments_url":"https://api.github.com/repos/tablexi/restforce-db/comments{/number}","issue_comment_url":"https://api.github.com/repos/tablexi/restforce-db/issues/comments{/number}","contents_url":"https://api.github.com/repos/tablexi/restforce-db/contents/{+path}","compare_url":"https://api.github.com/repos/tablexi/restforce-db/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tablexi/restforce-db/merges","archive_url":"https://api.github.com/repos/tablexi/restforce-db/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tablexi/restforce-db/downloads","issues_url":"https://api.github.com/repos/tablexi/restforce-db/issues{/number}","pulls_url":"https://api.github.com/repos/tablexi/restforce-db/pulls{/number}","milestones_url":"https://api.github.com/repos/tablexi/restforce-db/milestones{/number}","notifications_url":"https://api.github.com/repos/tablexi/restforce-db/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tablexi/restforce-db/labels{/name}","releases_url":"https://api.github.com/repos/tablexi/restforce-db/releases{/id}","created_at":"2015-03-17T23:04:27Z","updated_at":"2015-05-07T21:05:06Z","pushed_at":"2015-06-25T04:58:34Z","git_url":"git://github.com/tablexi/restforce-db.git","ssh_url":"git@github.com:tablexi/restforce-db.git","clone_url":"https://github.com/tablexi/restforce-db.git","svn_url":"https://github.com/tablexi/restforce-db","homepage":null,"size":1646,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/tablexi/restforce-db/pulls/48"},"html":{"href":"https://github.com/tablexi/restforce-db/pull/48"},"issue":{"href":"https://api.github.com/repos/tablexi/restforce-db/issues/48"},"comments":{"href":"https://api.github.com/repos/tablexi/restforce-db/issues/48/comments"},"review_comments":{"href":"https://api.github.com/repos/tablexi/restforce-db/pulls/48/comments"},"review_comment":{"href":"https://api.github.com/repos/tablexi/restforce-db/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/tablexi/restforce-db/pulls/48/commits"},"statuses":{"href":"https://api.github.com/repos/tablexi/restforce-db/statuses/da7889772aa4ca7592846b5c785c50e78afa34cb"}}}}