lib/fanforce/cli/app.rb in fanforce-cli-1.7.1 vs lib/fanforce/cli/app.rb in fanforce-cli-2.0.0.rc1
- old
+ new
@@ -1,57 +1,47 @@
class Fanforce::CLI::App
- attr_reader :_id, :dir, :dir_name, :dir_root, :root_domain
+ 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 self.load(dir); self.new(dir) end
+ ######################################################################################################################
+
def initialize(dir)
- raise "This is an invalid directory name for a fanforce addon: #{dir}" if dir !~ /^(.*)\/(app-([a-z0-9-]+))\/?$/
- @_id = $3
+ 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 create_files(*filenames)
- filenames.each do |filename|
- Fanforce::CLI::Files.method(:"create_#{filename}").call(self)
+ 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
- alias create_file create_files
- def update_files(*filenames)
- filenames.each do |filename|
- Fanforce::CLI::Files.method(:"update_#{filename}").call(self)
- end
- end
- alias update_file update_files
-
def to_hash
{
_id: @_id,
+ name: @name,
dir_name: @dir_name,
dir_root: @dir_root,
- dir: @dir,
+ dir: @dir
}
end
def to_json
to_hash.to_json
- end
-
- def start_print
- print "- #{@dir_name}... "
- end
-
- def end_print
- puts 'DONE'
end
end
\ No newline at end of file