{
  "$type": "site.standard.document",
  "description": "I described in Different Settings for Development and Adhoc Builds in RubyMotion how I set up my Rakefile to have an env variable that represents",
  "path": "/rubymotion-adhoc/",
  "publishedAt": "2014-04-30T08:01:00.000Z",
  "site": "at://did:plc:bryys25pc2fnagnyxqgsglhd/site.standard.publication/3mn26bjkkmh23",
  "tags": [
    "RubyMotion",
    "Techniques"
  ],
  "textContent": "I described in Different Settings for Development and Adhoc Builds in RubyMotion how I set up my Rakefile to have an env variable that represents whether the current build is for dev/adhoc/appstore. This env var helps so we can modify the configuration slightly (namely app.entitlements) accordingly.\n\nIn the app, we can't know if we are running an ad hoc build via something built-in or by accessing this env variable. We can't use RUBYMOTION_ENV since it has only these 3 possible values – test/development/release. (It is development for ad hoc builds). I have resorted to this workaround:\n\n1. I already have a module for each app, so I add these methods in there:\n\nmodule MyApp\n  def self.app_store?\n    RUBYMOTION_ENV == 'release'\n  end\n\n  #Definition is overridden via adhoc.rb for ad hoc builds\n  def self.adhoc?\n    false\n  end\n\n  def self.app_store_or_adhoc?\n    app_store? || adhoc?\n  end\n\n2. Create a file called adhoc.rb:\n\n#Sole responsibility of this file is to override MyApp.adhoc? to return true.\n#Add this file to the end of app.files if and only if it's an ad hoc build\nmodule MyApp\n  module_function\n\n  def self.adhoc?\n    true\n  end\nend\n\nadhoc.rb is at the root of the project, i.e. outside app/ so it isn't automatically included when building the project.\n\n3. Add this into Rakefile so adhoc.rb is included:\n\nMotion::Project::App.setup do |app|\n  if env == 'dev'\n    #...\n  elsif env == 'adhoc'\n    #...\n    app.files << \"./adhoc.rb\"\n  elsif env == 'appstore'\n    #...\n  end\nend\n\n4. In your app, you can now have a different code path for ad hoc builds:\n\nif MyApp.adhoc?\n  #...\nelse\n  #...\nend\n\nOr:\n\nif MyApp.app_store_or_adhoc?\n  #...\nelse\n  #...\nend\n\nI'm not sure if compilation order could cause a problem, but maybe updating app.files_dependencies will help with that. But given the way it's structured, any issue with loading order should be exposed during ad hoc testing and not affect app store distributions.",
  "title": "Different Code Paths For RubyMotion Ad hoc Builds"
}