Class: Billy::Commands::Eat

Inherits:
Command
  • Object
show all
Defined in:
lib/billy/commands/eat.rb

Instance Method Summary collapse

Methods inherited from Command

instance, #name, register_self!

Instance Method Details

#eat_config(config_string) ⇒ Object



27
28
29
# File 'lib/billy/commands/eat.rb', line 27

def eat_config( config_string )
  Billy::Config.instance.eat_string_config( config_string )
end

#file?(str) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/billy/commands/eat.rb', line 53

def file?( str )
  !uri?( str )
end

#load_remote_config(path) ⇒ Object



57
58
59
60
# File 'lib/billy/commands/eat.rb', line 57

def load_remote_config( path )
  uri = URI( path )
  Net::HTTP.get( uri )
end

#proceed!(arguments) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/billy/commands/eat.rb', line 9

def proceed!( arguments )
  ( path = arguments.shift ) unless arguments.nil?
  begin
    if path.nil? || path.empty?
      raise "No config path given. \nYou have to provide some settings path, e.g. in your local filesystem or direct link to blob file in repository etc."
    elsif uri?( path ) && ( result = load_remote_config( path ) ).nil?
      raise "Remote config file could not be loaded"
    elsif file?( path ) && ( !File.exists?( path ) || ( result = File.read( path ) ).nil? )
      raise "Config File not found: #{path}"
    end
  rescue Exception => e
    Billy::Util::UI.err e.message
    exit 1
  end
  eat_config( result )
  save_config
end

#save_configObject



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/billy/commands/eat.rb', line 31

def save_config
  Billy::Util::UI.inform "Parsed config data:"
  Billy::Config.settings.each_pair do |k, v|
    Billy::Util::UI.inform "#{k}: #{v}"
  end
  if !Billy::Util::UI.confirm? "Save this settings?(y/n): "
    Billy::Util::UI.inform "Billy didn't save config file. Skipping."
    exit 1
  end
  Billy::Config.save
  Billy::Util::UI.succ "Billy saved config file to #{Billy::Config::BILLYRC}"
end

#uri?(str) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
47
48
49
50
51
# File 'lib/billy/commands/eat.rb', line 44

def uri?( str )
  begin
    uri = URI.parse( str )
    %w( http https ).include?( uri.scheme )
  rescue
    false
  end
end