codekindly-utils 0.0.11 → 0.0.12
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.
- checksums.yaml +4 -4
 - data/lib/code_kindly/utils/active_record.rb +24 -12
 - data/lib/code_kindly/utils/file.rb +7 -1
 - data/lib/code_kindly/utils/version.rb +1 -1
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: de743298584863f0a05beb75a2e377f73209b84951eb1995efc9b71b5ad282c3
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 4ed210e67d01db161e0ba4d29a968d222647a7d212038919404fe55f0674e335
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: bd7f19cc3518d36dc8f72f77f23f39007beba9626e454120468218677d5f0ef3d9a1d978a0ebafaf394500f5435907a1cb641f179b83583ec596d2bd639231c3
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 59ffc1c1438ce65409b394f4d400a024b8f37cafd403081e22f088d9add2edaabe381cf2833cdc0fabff91b55a765720f0f0c6f5bf8fca2c2ef84212b4d2b569
         
     | 
| 
         @@ -34,9 +34,18 @@ module CodeKindly 
     | 
|
| 
       34 
34 
     | 
    
         
             
                      configs[name || default_name]
         
     | 
| 
       35 
35 
     | 
    
         
             
                    end
         
     | 
| 
       36 
36 
     | 
    
         | 
| 
      
 37 
     | 
    
         
            +
                    # rubocop:disable Security/YAMLLoad
         
     | 
| 
       37 
38 
     | 
    
         
             
                    def configs
         
     | 
| 
       38 
39 
     | 
    
         
             
                      @configs ||= ::ActiveRecord::Base.configurations
         
     | 
| 
      
 40 
     | 
    
         
            +
                      return @configs unless @configs == {}
         
     | 
| 
      
 41 
     | 
    
         
            +
                      return @configs unless RAILS.respond_to?(:root)
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                      file = RAILS.root.join('config', 'database.yml')
         
     | 
| 
      
 44 
     | 
    
         
            +
                      return @configs unless ::File.readable?(file)
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
                      @configs = YAML.load(::File.read(file))
         
     | 
| 
       39 
47 
     | 
    
         
             
                    end
         
     | 
| 
      
 48 
     | 
    
         
            +
                    # rubocop:enable Security/YAMLLoad
         
     | 
| 
       40 
49 
     | 
    
         | 
| 
       41 
50 
     | 
    
         
             
                    def configurations
         
     | 
| 
       42 
51 
     | 
    
         
             
                      deprecate :configurations, :configs, :'0.1.0'
         
     | 
| 
         @@ -61,6 +70,7 @@ module CodeKindly 
     | 
|
| 
       61 
70 
     | 
    
         
             
                      return false     if klass.abstract_class
         
     | 
| 
       62 
71 
     | 
    
         
             
                      return false     if klass.name =~ /ActiveRecord::/
         
     | 
| 
       63 
72 
     | 
    
         
             
                      return false     if Presence.blank?(klass.name)
         
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
       64 
74 
     | 
    
         
             
                      true
         
     | 
| 
       65 
75 
     | 
    
         
             
                    rescue NoMethodError
         
     | 
| 
       66 
76 
     | 
    
         
             
                      false
         
     | 
| 
         @@ -70,23 +80,14 @@ module CodeKindly 
     | 
|
| 
       70 
80 
     | 
    
         
             
                      @default_name ||= RAILS.try(:env) || configs.keys.first || 'default'
         
     | 
| 
       71 
81 
     | 
    
         
             
                    end
         
     | 
| 
       72 
82 
     | 
    
         | 
| 
       73 
     | 
    
         
            -
                    # rubocop:disable Metrics/AbcSize
         
     | 
| 
       74 
83 
     | 
    
         
             
                    def find_classes
         
     | 
| 
       75 
     | 
    
         
            -
                       
     | 
| 
       76 
     | 
    
         
            -
                        model_files = RAILS.root.join('app', 'models').to_s + '/**/*.rb'
         
     | 
| 
       77 
     | 
    
         
            -
                        ::Dir.glob(model_files) do |f|
         
     | 
| 
       78 
     | 
    
         
            -
                          klass = ::File.basename(f, '.rb').classify
         
     | 
| 
       79 
     | 
    
         
            -
                          next if Kernel.const_defined? klass
         
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
       81 
     | 
    
         
            -
                          require f
         
     | 
| 
       82 
     | 
    
         
            -
                        end
         
     | 
| 
       83 
     | 
    
         
            -
                      end
         
     | 
| 
      
 84 
     | 
    
         
            +
                      load_classes_in_development
         
     | 
| 
       84 
85 
     | 
    
         
             
                      ObjectSpace.each_object(Class).select do |klass|
         
     | 
| 
       85 
86 
     | 
    
         
             
                        application_active_record_class?(klass)
         
     | 
| 
       86 
87 
     | 
    
         
             
                      end.sort_by(&:name)
         
     | 
| 
       87 
88 
     | 
    
         
             
                    end
         
     | 
| 
       88 
89 
     | 
    
         | 
| 
       89 
     | 
    
         
            -
                    def find_classes_by_connection
         
     | 
| 
      
 90 
     | 
    
         
            +
                    def find_classes_by_connection # rubocop:disable Metrics/AbcSize
         
     | 
| 
       90 
91 
     | 
    
         
             
                      sets = {}.with_indifferent_access
         
     | 
| 
       91 
92 
     | 
    
         
             
                      find_classes.each do |klass|
         
     | 
| 
       92 
93 
     | 
    
         
             
                        config_name = configs.keys.select do |k|
         
     | 
| 
         @@ -98,7 +99,18 @@ module CodeKindly 
     | 
|
| 
       98 
99 
     | 
    
         
             
                      end
         
     | 
| 
       99 
100 
     | 
    
         
             
                      sets
         
     | 
| 
       100 
101 
     | 
    
         
             
                    end
         
     | 
| 
       101 
     | 
    
         
            -
             
     | 
| 
      
 102 
     | 
    
         
            +
             
     | 
| 
      
 103 
     | 
    
         
            +
                    def load_classes_in_development
         
     | 
| 
      
 104 
     | 
    
         
            +
                      return unless RAILS.try(:env).try(:development?)
         
     | 
| 
      
 105 
     | 
    
         
            +
             
     | 
| 
      
 106 
     | 
    
         
            +
                      model_files = RAILS.root.join('app', 'models').to_s + '/**/*.rb'
         
     | 
| 
      
 107 
     | 
    
         
            +
                      ::Dir.glob(model_files) do |f|
         
     | 
| 
      
 108 
     | 
    
         
            +
                        klass = ::File.basename(f, '.rb').classify
         
     | 
| 
      
 109 
     | 
    
         
            +
                        next if Kernel.const_defined? klass
         
     | 
| 
      
 110 
     | 
    
         
            +
             
     | 
| 
      
 111 
     | 
    
         
            +
                        require f
         
     | 
| 
      
 112 
     | 
    
         
            +
                      end
         
     | 
| 
      
 113 
     | 
    
         
            +
                    end
         
     | 
| 
       102 
114 
     | 
    
         
             
                  end
         
     | 
| 
       103 
115 
     | 
    
         
             
                end
         
     | 
| 
       104 
116 
     | 
    
         
             
              end
         
     | 
| 
         @@ -15,10 +15,12 @@ module CodeKindly 
     | 
|
| 
       15 
15 
     | 
    
         
             
                      h_l ||= HighLine.new
         
     | 
| 
       16 
16 
     | 
    
         
             
                      file_opts = file_options(dir_path)
         
     | 
| 
       17 
17 
     | 
    
         
             
                      return nil if blank? file_opts
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
       18 
19 
     | 
    
         
             
                      msg = file_opts.inject('') { |(k, v), m| m + "\n  #{k}: #{v}" }
         
     | 
| 
       19 
20 
     | 
    
         
             
                      option = h_l.ask("Select a file:#{msg}\n  0: None", Integer)
         
     | 
| 
       20 
21 
     | 
    
         
             
                      file_path = file_opts.fetch(option, nil)
         
     | 
| 
       21 
22 
     | 
    
         
             
                      return if file_path.nil?
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
       22 
24 
     | 
    
         
             
                      ::File.join(dir_path, file_path)
         
     | 
| 
       23 
25 
     | 
    
         
             
                    end
         
     | 
| 
       24 
26 
     | 
    
         | 
| 
         @@ -40,13 +42,17 @@ module CodeKindly 
     | 
|
| 
       40 
42 
     | 
    
         
             
                    # move to trash (or delete) existing downloaded files
         
     | 
| 
       41 
43 
     | 
    
         
             
                    # sudo gem install osx-trash (http://www.dribin.org/dave/blog/archives/2008/05/24/osx_trash/)
         
     | 
| 
       42 
44 
     | 
    
         
             
                    def trash!(file_string)
         
     | 
| 
       43 
     | 
    
         
            -
                       
     | 
| 
      
 45 
     | 
    
         
            +
                      command = command_to_trash_files(file_string)
         
     | 
| 
      
 46 
     | 
    
         
            +
                      return if command.nil?
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
                      Kernel.system(command)
         
     | 
| 
       44 
49 
     | 
    
         
             
                    end
         
     | 
| 
       45 
50 
     | 
    
         | 
| 
       46 
51 
     | 
    
         
             
                    private
         
     | 
| 
       47 
52 
     | 
    
         | 
| 
       48 
53 
     | 
    
         
             
                    def command_to_trash_files(file_string)
         
     | 
| 
       49 
54 
     | 
    
         
             
                      return if Command.run("ls #{file_string}").result.nil?
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
       50 
56 
     | 
    
         
             
                      trash = OS.which('trash')
         
     | 
| 
       51 
57 
     | 
    
         
             
                      if trash then "#{trash.chomp} #{file_string}"
         
     | 
| 
       52 
58 
     | 
    
         
             
                      elsif ::File.directory?('~/.Trash') then "mv #{file_string} ~/.Trash"
         
     |