lib/appinit.rb in forj-1.0.3 vs lib/appinit.rb in forj-1.0.4
- old
+ new
@@ -12,41 +12,30 @@
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-
-require 'lorj'
-
# Module to initialize the application
# TODO: Cleanup about Global variables used. Should be replaced by PrcLib
# or other kind of setting.
-module AppInit
+module Forj
+ class << self
+ attr_accessor :build_path, :keypairs_path
+ end
- def AppInit.forj_initialize()
- # Function to create FORJ paths if missing.
+ module_function
- # Defining Global variables
- $FORJ_DATA_PATH = File.expand_path(File.join('~', '.forj'))
- $FORJ_ACCOUNTS_PATH = File.join($FORJ_DATA_PATH, 'accounts')
- $FORJ_KEYPAIRS_PATH = File.join($FORJ_DATA_PATH, 'keypairs')
- $FORJ_BUILD_PATH = File.join($FORJ_DATA_PATH, '.build')
- $FORJ_CREDS_PATH = File.expand_path(File.join('~', '.cache', 'forj'))
+ def keypairs_path=(v)
+ @keypairs_path = File.expand_path(v) unless @keypairs_path
+ PrcLib.ensure_dir_exists(@keypairs_path)
+ begin
+ FileUtils.chmod(0700, @keypairs_path) # no-op on windows
+ rescue => e
+ fatal_error(1, e.message)
+ end
+ end
- # TODO: To move to an hpcloud object.
- $HPC_KEYPAIRS = File.expand_path(File.join('~', '.hpcloud', 'keypairs'))
- $HPC_ACCOUNTS = File.expand_path(File.join('~', '.hpcloud', 'accounts'))
-
- AppInit.ensure_dir_exists($FORJ_DATA_PATH)
- AppInit.ensure_dir_exists($FORJ_ACCOUNTS_PATH)
- AppInit.ensure_dir_exists($FORJ_BUILD_PATH)
- AppInit.ensure_dir_exists($FORJ_KEYPAIRS_PATH)
- FileUtils.chmod(0700, $FORJ_KEYPAIRS_PATH)
- AppInit.ensure_dir_exists($FORJ_CREDS_PATH)
- end
-
- def AppInit.ensure_dir_exists(path)
- if not PrcLib.dir_exists?(path)
- FileUtils.mkpath(path) if not File.directory?(path)
- end
- end
+ def build_path=(v)
+ @build_path = File.expand_path(v) unless @build_path
+ PrcLib.ensure_dir_exists(@build_path)
+ end
end