chekku 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/chekku/definition.rb +1 -1
 - data/lib/chekku/definitions.rb +5 -0
 - data/lib/chekku/errors.rb +1 -0
 - data/lib/chekku/fetcher.rb +4 -4
 - data/lib/chekku/installer.rb +35 -0
 - data/lib/chekku/version.rb +1 -1
 - data/spec/lib/definition_spec.rb +1 -1
 - metadata +2 -1
 
    
        data/lib/chekku/definition.rb
    CHANGED
    
    | 
         @@ -45,7 +45,7 @@ module Chekku 
     | 
|
| 
       45 
45 
     | 
    
         
             
                # @raise [AppNameNotStringError] if Definition is not correct and executable isn't a string
         
     | 
| 
       46 
46 
     | 
    
         
             
                # @raise [AppNameNotSaneError] if Definition executable isn't safe (spaces, special chars and so on)
         
     | 
| 
       47 
47 
     | 
    
         
             
                def chekku!(version = nil, args = {})
         
     | 
| 
       48 
     | 
    
         
            -
                  raise( 
     | 
| 
      
 48 
     | 
    
         
            +
                  raise(NotInstalledError, "not installed") unless exists?
         
     | 
| 
       49 
49 
     | 
    
         
             
                  validates version, args
         
     | 
| 
       50 
50 
     | 
    
         
             
                end
         
     | 
| 
       51 
51 
     | 
    
         | 
    
        data/lib/chekku/definitions.rb
    CHANGED
    
    | 
         @@ -1,6 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            #encoding: utf-8
         
     | 
| 
       2 
2 
     | 
    
         
             
            require_relative 'definition'
         
     | 
| 
       3 
3 
     | 
    
         
             
            require_relative 'definitions_service'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require_relative 'installer'
         
     | 
| 
       4 
5 
     | 
    
         | 
| 
       5 
6 
     | 
    
         
             
            class Chekku::Definitions
         
     | 
| 
       6 
7 
     | 
    
         | 
| 
         @@ -17,6 +18,7 @@ class Chekku::Definitions 
     | 
|
| 
       17 
18 
     | 
    
         
             
              def initialize
         
     | 
| 
       18 
19 
     | 
    
         
             
                @definitions_service = Chekku::DefinitionsService.new
         
     | 
| 
       19 
20 
     | 
    
         
             
                @definitions_service.load_definitions_for @chekkufile
         
     | 
| 
      
 21 
     | 
    
         
            +
                @installer ||= Chekku::Installer.new
         
     | 
| 
       20 
22 
     | 
    
         
             
              end
         
     | 
| 
       21 
23 
     | 
    
         | 
| 
       22 
24 
     | 
    
         
             
              # Parse the file and evaluate every dependency
         
     | 
| 
         @@ -47,6 +49,9 @@ class Chekku::Definitions 
     | 
|
| 
       47 
49 
     | 
    
         
             
                puts "[\033[31m✗\033[0m] #{name}: #{e.message}\n"
         
     | 
| 
       48 
50 
     | 
    
         
             
              rescue ChekkuError => e
         
     | 
| 
       49 
51 
     | 
    
         
             
                puts "\033[31mERROR: #{e.message}\033[0m\n"
         
     | 
| 
      
 52 
     | 
    
         
            +
              rescue NotInstalledError => e
         
     | 
| 
      
 53 
     | 
    
         
            +
                puts "[\033[31m✗\033[0m] #{name}: #{e.message}\n"
         
     | 
| 
      
 54 
     | 
    
         
            +
                @installer.install_app? name
         
     | 
| 
       50 
55 
     | 
    
         
             
              end
         
     | 
| 
       51 
56 
     | 
    
         | 
| 
       52 
57 
     | 
    
         
             
              # Retrieve the Definition instance from the DefinitionService
         
     | 
    
        data/lib/chekku/errors.rb
    CHANGED
    
    
    
        data/lib/chekku/fetcher.rb
    CHANGED
    
    | 
         @@ -43,10 +43,10 @@ class Chekku::Fetcher 
     | 
|
| 
       43 
43 
     | 
    
         | 
| 
       44 
44 
     | 
    
         
             
              def ensure_definitions_are_up_to_date(definitions_yaml)
         
     | 
| 
       45 
45 
     | 
    
         
             
                last_updated = definitions_yaml.delete('updated_at')
         
     | 
| 
       46 
     | 
    
         
            -
                 
     | 
| 
       47 
     | 
    
         
            -
                   
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
                   
     | 
| 
      
 46 
     | 
    
         
            +
                if too_long_ago?(last_updated)
         
     | 
| 
      
 47 
     | 
    
         
            +
                  fetch_new_distant_definitions
         
     | 
| 
      
 48 
     | 
    
         
            +
                else
         
     | 
| 
      
 49 
     | 
    
         
            +
                  definitions_yaml
         
     | 
| 
       50 
50 
     | 
    
         
             
                end
         
     | 
| 
       51 
51 
     | 
    
         
             
              end
         
     | 
| 
       52 
52 
     | 
    
         | 
| 
         @@ -0,0 +1,35 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #encoding: utf-8
         
     | 
| 
      
 2 
     | 
    
         
            +
            class Chekku::Installer
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
              def install_app?(app_name)
         
     | 
| 
      
 5 
     | 
    
         
            +
                return if @never_install
         
     | 
| 
      
 6 
     | 
    
         
            +
                install_answer = ask_user(app_name) unless @install_all
         
     | 
| 
      
 7 
     | 
    
         
            +
                @never_install = true if install_answer == 'none'
         
     | 
| 
      
 8 
     | 
    
         
            +
                @install_all = true   if install_answer == 'all' || install_answer == 'a'
         
     | 
| 
      
 9 
     | 
    
         
            +
                if @install_all || install_answer == 'yes' || install_answer == 'y'
         
     | 
| 
      
 10 
     | 
    
         
            +
                  puts "Starting #{app_name} installation"
         
     | 
| 
      
 11 
     | 
    
         
            +
                  install_app app_name
         
     | 
| 
      
 12 
     | 
    
         
            +
                end
         
     | 
| 
      
 13 
     | 
    
         
            +
              end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
              private
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
              def ask_user(app_name)
         
     | 
| 
      
 18 
     | 
    
         
            +
                print "Would you like to install #{app_name}? (y)es/(n)o/(a)ll/none : "
         
     | 
| 
      
 19 
     | 
    
         
            +
                gets.downcase.chomp
         
     | 
| 
      
 20 
     | 
    
         
            +
              end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
              def install_app(app_name)
         
     | 
| 
      
 23 
     | 
    
         
            +
                if RbConfig::CONFIG['host_os'].include? 'darwin'
         
     | 
| 
      
 24 
     | 
    
         
            +
                  system "brew install #{app_name}"
         
     | 
| 
      
 25 
     | 
    
         
            +
                  if $?.exitstatus == 0
         
     | 
| 
      
 26 
     | 
    
         
            +
                    "Installation of #{app_name} done"
         
     | 
| 
      
 27 
     | 
    
         
            +
                  else
         
     | 
| 
      
 28 
     | 
    
         
            +
                    "Installation of #{app_name} failed"
         
     | 
| 
      
 29 
     | 
    
         
            +
                  end
         
     | 
| 
      
 30 
     | 
    
         
            +
                else
         
     | 
| 
      
 31 
     | 
    
         
            +
                  puts "[\033[31m✗\033[0m] We Only support OSX for installation for the moment\n"
         
     | 
| 
      
 32 
     | 
    
         
            +
                end
         
     | 
| 
      
 33 
     | 
    
         
            +
              end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/chekku/version.rb
    CHANGED
    
    
    
        data/spec/lib/definition_spec.rb
    CHANGED
    
    | 
         @@ -85,7 +85,7 @@ describe Chekku::Definition do 
     | 
|
| 
       85 
85 
     | 
    
         | 
| 
       86 
86 
     | 
    
         
             
                it 'should says x if soft does not exist' do
         
     | 
| 
       87 
87 
     | 
    
         
             
                  definition.stub(:exists?).and_return(false)
         
     | 
| 
       88 
     | 
    
         
            -
                  expect { definition.chekku! }.to raise_error( 
     | 
| 
      
 88 
     | 
    
         
            +
                  expect { definition.chekku! }.to raise_error(NotInstalledError)
         
     | 
| 
       89 
89 
     | 
    
         
             
                end
         
     | 
| 
       90 
90 
     | 
    
         
             
              end
         
     | 
| 
       91 
91 
     | 
    
         | 
    
        metadata
    CHANGED
    
    | 
         @@ -2,7 +2,7 @@ 
     | 
|
| 
       2 
2 
     | 
    
         
             
            name: chekku
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
4 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       5 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 5 
     | 
    
         
            +
              version: 0.6.0
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors:
         
     | 
| 
       8 
8 
     | 
    
         
             
            - Yannick Schutz
         
     | 
| 
         @@ -101,6 +101,7 @@ files: 
     | 
|
| 
       101 
101 
     | 
    
         
             
            - lib/chekku/definitions_service.rb
         
     | 
| 
       102 
102 
     | 
    
         
             
            - lib/chekku/errors.rb
         
     | 
| 
       103 
103 
     | 
    
         
             
            - lib/chekku/fetcher.rb
         
     | 
| 
      
 104 
     | 
    
         
            +
            - lib/chekku/installer.rb
         
     | 
| 
       104 
105 
     | 
    
         
             
            - lib/chekku/version.rb
         
     | 
| 
       105 
106 
     | 
    
         
             
            - spec/lib/definition_spec.rb
         
     | 
| 
       106 
107 
     | 
    
         
             
            - spec/lib/definitions_service_spec.rb
         
     |