Class: Zmeygo::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/zmeygo/command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Command

Returns a new instance of Command.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/zmeygo/command.rb', line 7

def initialize(options)
	if options[:init]
		src_file = File.join(File.dirname(__FILE__),'../..','templates','zmeygo.yml.template')
		dest_dir = File.expand_path(
        File.dirname(Constant::DEFAULT_CONFIG_FILE)
      )
		dest_file = File.expand_path(Constant::DEFAULT_CONFIG_FILE)
		unless File.exists?(dest_dir)
			FileUtils.mkdir_p dest_dir
		end
      unless File.exists?(dest_file)
        puts "Creating config file #{dest_file}..."
        system "cp #{src_file} #{dest_file}"
        puts "Done."
        exit
      else
        puts "config file #{Constant::DEFAULT_CONFIG_FILE} already exists. Nothing to do."
      end
	end

  Zmeygo.configure

	self.options = options
	self.client = Zmeygo::Client.new(options)

	[:push,:pull,:list, :ping].each do |command|
	 	ret = client.send(command) if options[command]
      if ret.present?
        puts ret
      end
	end
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



5
6
7
# File 'lib/zmeygo/command.rb', line 5

def client
  @client
end

#optionsObject

Returns the value of attribute options.



5
6
7
# File 'lib/zmeygo/command.rb', line 5

def options
  @options
end