class Fanforce::CLI::App attr_reader :_id, :dir, :dir_name, :dir_root, :root_domain, :name def self.parse_dir_name(dir_name) return if dir_name !~ /^(app-([a-z0-9-]+))\/?$/ {_id: $2, dir_name: $1} end def self.load(dir); self.new(dir) end ###################################################################################################################### def initialize(dir) raise "This is an invalid directory name for a fanforce addon: #{dir}" if dir !~ /^(.*)\/([a-z0-9-]+)\/?$/ @_id = $2 @dir = "#{$1}/#{$2}" @dir_root = $1 @dir_name = $2 @root_domain = Fanforce.apps_base_domain @name = @_id.gsub('-', ' ').titleize end def config @config ||= begin file_path = "#{@dir}/config.json" return {} if !File.exists?(file_path) file = File.open(file_path).read MultiJson.load(file, symbolize_keys: true) end end def to_hash { _id: @_id, name: @name, dir_name: @dir_name, dir_root: @dir_root, dir: @dir } end def to_json to_hash.to_json end end