obfs 0.0.1
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 +7 -0
 - data/lib/obfs.rb +107 -0
 - metadata +43 -0
 
    
        checksums.yaml
    ADDED
    
    | 
         @@ -0,0 +1,7 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            ---
         
     | 
| 
      
 2 
     | 
    
         
            +
            SHA256:
         
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 60ad552589248d9ac27f0560e71ad3ddd4dfd32407c50fc4c10ee9732b17945a
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 89bfcf071f49f51bc9ad25768c4fdc9e3e7b1c67a9305c7f6aaa358859798ed4
         
     | 
| 
      
 5 
     | 
    
         
            +
            SHA512:
         
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 64ec76f87128169a5cad3d118dd8b13bf08a4fe2841e7b0b312fbd1f93becbf00e652a8da21466ed85c14e9f42523c723bca51e429b7cef28fb254f5073f79ef
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 3389becdd8b5533ee7883b95907071bcaa77c5a2e9a54a7a7bbd89da7a758a4819ec525691dd244905c5f7fcb2443682a4a641a29ac8b1d891b370fc6b3c99cf
         
     | 
    
        data/lib/obfs.rb
    ADDED
    
    | 
         @@ -0,0 +1,107 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # dependencies
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'fileutils'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'json'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'text'
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            # main
         
     | 
| 
      
 7 
     | 
    
         
            +
            class OBFS
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                    def initialize(attributes = {}) # hash argument
         
     | 
| 
      
 10 
     | 
    
         
            +
                        @path = (attributes.keys.include? :path) ? attributes[:path] : (File.join(Dir.home, '.obfs'))
         
     | 
| 
      
 11 
     | 
    
         
            +
                    end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                    # regular methods
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                    def method_missing(m, *args, &block)
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                        # normalize
         
     | 
| 
      
 18 
     | 
    
         
            +
                        method_name = m.to_s
         
     | 
| 
      
 19 
     | 
    
         
            +
                        dataA = args[0]
         
     | 
| 
      
 20 
     | 
    
         
            +
                        dataB = args[1]
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                        # setter call
         
     | 
| 
      
 23 
     | 
    
         
            +
                        if  method_name.end_with?('=')
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                            # clean up name
         
     | 
| 
      
 26 
     | 
    
         
            +
                            method_name = method_name.gsub('=','')
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                            # reassign if square bracket notation
         
     | 
| 
      
 29 
     | 
    
         
            +
                            if method_name == "[]"
         
     | 
| 
      
 30 
     | 
    
         
            +
                                method_name = dataA
         
     | 
| 
      
 31 
     | 
    
         
            +
                                data = dataB
         
     | 
| 
      
 32 
     | 
    
         
            +
                            else # make sure we load the proper method_name and data
         
     | 
| 
      
 33 
     | 
    
         
            +
                                method_name = m.to_s.gsub('=','')
         
     | 
| 
      
 34 
     | 
    
         
            +
                                data = args[0]
         
     | 
| 
      
 35 
     | 
    
         
            +
                            end
         
     | 
| 
      
 36 
     | 
    
         
            +
                                
         
     | 
| 
      
 37 
     | 
    
         
            +
                            # write data
         
     | 
| 
      
 38 
     | 
    
         
            +
                            if data == nil
         
     | 
| 
      
 39 
     | 
    
         
            +
                                FileUtils.rm_rf File.join @path, method_name
         
     | 
| 
      
 40 
     | 
    
         
            +
                            else
         
     | 
| 
      
 41 
     | 
    
         
            +
                                FileUtils.rm_rf @path, method_name if File.exist? File.join @path, method_name
         
     | 
| 
      
 42 
     | 
    
         
            +
                                FileUtils.mkpath @path if !File.directory? @path
         
     | 
| 
      
 43 
     | 
    
         
            +
                                write(@path, method_name, data)
         
     | 
| 
      
 44 
     | 
    
         
            +
                            end
         
     | 
| 
      
 45 
     | 
    
         
            +
                        
         
     | 
| 
      
 46 
     | 
    
         
            +
                        # bracket notation
         
     | 
| 
      
 47 
     | 
    
         
            +
                        elsif method_name == "[]"
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
                            method_name = dataA.to_s.gsub(/\["/,'').gsub(/"\]/,'')
         
     | 
| 
      
 50 
     | 
    
         
            +
                            if (!File.directory? File.join(@path, method_name)) && (File.exist? File.join(@path, method_name))
         
     | 
| 
      
 51 
     | 
    
         
            +
                                read(@path, method_name)
         
     | 
| 
      
 52 
     | 
    
         
            +
                            else
         
     | 
| 
      
 53 
     | 
    
         
            +
                                OBFS.new({ path: File.join(@path, method_name.to_s) })
         
     | 
| 
      
 54 
     | 
    
         
            +
                            end
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
                        # recurse or read
         
     | 
| 
      
 57 
     | 
    
         
            +
                        else
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
                            if (!File.directory? File.join(@path, method_name)) && (File.exist? File.join(@path, method_name))
         
     | 
| 
      
 60 
     | 
    
         
            +
                                read(@path, method_name)
         
     | 
| 
      
 61 
     | 
    
         
            +
                            else
         
     | 
| 
      
 62 
     | 
    
         
            +
                                OBFS.new({ path: File.join(@path, method_name.to_s) })
         
     | 
| 
      
 63 
     | 
    
         
            +
                            end
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
                        end
         
     | 
| 
      
 66 
     | 
    
         
            +
                        
         
     | 
| 
      
 67 
     | 
    
         
            +
                    end
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
                    # special methods
         
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
      
 71 
     | 
    
         
            +
                    # returns current working path for obfs
         
     | 
| 
      
 72 
     | 
    
         
            +
                    def _path
         
     | 
| 
      
 73 
     | 
    
         
            +
                        @path
         
     | 
| 
      
 74 
     | 
    
         
            +
                    end
         
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
      
 76 
     | 
    
         
            +
                    # returns directory contents in an array
         
     | 
| 
      
 77 
     | 
    
         
            +
                    def _index
         
     | 
| 
      
 78 
     | 
    
         
            +
                        Dir.entries(@path).reject { |k| k == '.' || k == '..' } rescue nil
         
     | 
| 
      
 79 
     | 
    
         
            +
                    end
         
     | 
| 
      
 80 
     | 
    
         
            +
             
     | 
| 
      
 81 
     | 
    
         
            +
                    # searches directory contents (1 level) and returns array sorted by relevance
         
     | 
| 
      
 82 
     | 
    
         
            +
                    def _find(term = '', records = 10, tolerance = 10)
         
     | 
| 
      
 83 
     | 
    
         
            +
                        output = []
         
     | 
| 
      
 84 
     | 
    
         
            +
                        search_space = Dir.entries(@path).reject { |k| k == '.' || k == '..' } rescue []
         
     | 
| 
      
 85 
     | 
    
         
            +
                        search_space.each do |search_space_term|
         
     | 
| 
      
 86 
     | 
    
         
            +
                            if Text::Levenshtein.distance(search_space_term, term) <= tolerance && Text::WhiteSimilarity.similarity(search_space_term, term) > 0.0
         
     | 
| 
      
 87 
     | 
    
         
            +
                                output << search_space_term
         
     | 
| 
      
 88 
     | 
    
         
            +
                            end
         
     | 
| 
      
 89 
     | 
    
         
            +
                        end
         
     | 
| 
      
 90 
     | 
    
         
            +
                        output.first(records)
         
     | 
| 
      
 91 
     | 
    
         
            +
                    end 
         
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
| 
      
 93 
     | 
    
         
            +
                    private
         
     | 
| 
      
 94 
     | 
    
         
            +
             
     | 
| 
      
 95 
     | 
    
         
            +
                    # filesystem R/W
         
     | 
| 
      
 96 
     | 
    
         
            +
             
     | 
| 
      
 97 
     | 
    
         
            +
                    def write(path, filename, data)
         
     | 
| 
      
 98 
     | 
    
         
            +
                        curr_path = File.join path, filename
         
     | 
| 
      
 99 
     | 
    
         
            +
                        File.write(curr_path, JSON.unparse(data))
         
     | 
| 
      
 100 
     | 
    
         
            +
                    end
         
     | 
| 
      
 101 
     | 
    
         
            +
             
     | 
| 
      
 102 
     | 
    
         
            +
                    def read(path, filename)
         
     | 
| 
      
 103 
     | 
    
         
            +
                        curr_path = File.join path, filename
         
     | 
| 
      
 104 
     | 
    
         
            +
                        JSON.parse(File.open(curr_path).read) rescue File.open(curr_path).read
         
     | 
| 
      
 105 
     | 
    
         
            +
                    end
         
     | 
| 
      
 106 
     | 
    
         
            +
             
     | 
| 
      
 107 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    ADDED
    
    | 
         @@ -0,0 +1,43 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification
         
     | 
| 
      
 2 
     | 
    
         
            +
            name: obfs
         
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version
         
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.1
         
     | 
| 
      
 5 
     | 
    
         
            +
            platform: ruby
         
     | 
| 
      
 6 
     | 
    
         
            +
            authors:
         
     | 
| 
      
 7 
     | 
    
         
            +
            - Jensel Gatchalian
         
     | 
| 
      
 8 
     | 
    
         
            +
            autorequire: 
         
     | 
| 
      
 9 
     | 
    
         
            +
            bindir: bin
         
     | 
| 
      
 10 
     | 
    
         
            +
            cert_chain: []
         
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2021-01-16 00:00:00.000000000 Z
         
     | 
| 
      
 12 
     | 
    
         
            +
            dependencies: []
         
     | 
| 
      
 13 
     | 
    
         
            +
            description: File-based, object-oriented data store for Ruby
         
     | 
| 
      
 14 
     | 
    
         
            +
            email: jensel.gatchalian@gmail.com
         
     | 
| 
      
 15 
     | 
    
         
            +
            executables: []
         
     | 
| 
      
 16 
     | 
    
         
            +
            extensions: []
         
     | 
| 
      
 17 
     | 
    
         
            +
            extra_rdoc_files: []
         
     | 
| 
      
 18 
     | 
    
         
            +
            files:
         
     | 
| 
      
 19 
     | 
    
         
            +
            - lib/obfs.rb
         
     | 
| 
      
 20 
     | 
    
         
            +
            homepage: https://rubygems.org/gems/obfs
         
     | 
| 
      
 21 
     | 
    
         
            +
            licenses:
         
     | 
| 
      
 22 
     | 
    
         
            +
            - MIT
         
     | 
| 
      
 23 
     | 
    
         
            +
            metadata: {}
         
     | 
| 
      
 24 
     | 
    
         
            +
            post_install_message: 
         
     | 
| 
      
 25 
     | 
    
         
            +
            rdoc_options: []
         
     | 
| 
      
 26 
     | 
    
         
            +
            require_paths:
         
     | 
| 
      
 27 
     | 
    
         
            +
            - lib
         
     | 
| 
      
 28 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 29 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 30 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 31 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 32 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 33 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 34 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 35 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 36 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 37 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 38 
     | 
    
         
            +
            requirements: []
         
     | 
| 
      
 39 
     | 
    
         
            +
            rubygems_version: 3.2.3
         
     | 
| 
      
 40 
     | 
    
         
            +
            signing_key: 
         
     | 
| 
      
 41 
     | 
    
         
            +
            specification_version: 4
         
     | 
| 
      
 42 
     | 
    
         
            +
            summary: OBFS
         
     | 
| 
      
 43 
     | 
    
         
            +
            test_files: []
         
     |