onlyoffice_file_helper 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7754ee429ce8e9954dd7c3343650bb29564dd44f762cd35c1de5b922773a2e47
4
- data.tar.gz: 832ae50c2ea5275ef193887e88611626c7c7f365c90536711f6db3df8b1c6938
3
+ metadata.gz: 960f7f59f836fb2dbbdb528ce155c265cb92e380557fa758465686612d4e7176
4
+ data.tar.gz: c0b2363e46bbf0ec44824caa4ba9a6085b0eab20597d9e021fe9f4f2447281ed
5
5
  SHA512:
6
- metadata.gz: 295ec48c909d4c48081f62b99d6631ae206926ef6a10a08b725ae3de3ea58e50740e260cb6e9ac9c2a4993bc0d0dbfc6dace4075f13ffc249115635c4f652a3f
7
- data.tar.gz: fce67d533563eaba672b4346f41a779fee4861e6372d752964052f6e2c105a2151dfd4fa97918d89a6321b2d5296a4f1a48c33821015aa63055e86f14de88889
6
+ metadata.gz: 5483180cd580bd34697f23787630bad8eb72e1b879cbde1af1e22473829c07d36dfe73d0bb5834c4897d9e95d808f12cff6daeb5cb0f42c819abc99152185f3e
7
+ data.tar.gz: be52527e07d845c960724fa3a2ddbac3a7e31465bd3d8be6792a91a30a3663a673193bd5d7aeeb64d51caab1d62427cca33bd49f3cdc426bf9ce6d14a9b18e76
@@ -10,8 +10,10 @@ require 'onlyoffice_file_helper/directory_methods'
10
10
  require 'onlyoffice_file_helper/read_methods'
11
11
  require 'onlyoffice_file_helper/version'
12
12
  require 'onlyoffice_file_helper/linux_helper'
13
+ require 'onlyoffice_file_helper/ruby_helper'
13
14
  require 'onlyoffice_file_helper/string_helper'
14
15
 
16
+ # Namespace of project
15
17
  module OnlyofficeFileHelper
16
18
  # Stuff for working with Files
17
19
  class FileHelper
@@ -29,6 +31,10 @@ module OnlyofficeFileHelper
29
31
  name.to_s
30
32
  end
31
33
 
34
+ # Wait for downloading file
35
+ # @param path [String] path to waiting download
36
+ # @param timeout [Integer] timeout to wait
37
+ # @return [True, False] result
32
38
  def wait_file_to_download(path, timeout = 300)
33
39
  timer = 0
34
40
  OnlyofficeLoggerHelper.log("Start waiting to download file: #{path}")
@@ -42,6 +48,10 @@ module OnlyofficeFileHelper
42
48
  timer <= timeout
43
49
  end
44
50
 
51
+ # Extract archive to folder
52
+ # @param path_to_archive [String] path of file
53
+ # @param path_to_extract [String] result path
54
+ # @return [Void]
45
55
  def extract_to_folder(path_to_archive,
46
56
  path_to_extract = path_to_archive.chomp(File.basename(path_to_archive)))
47
57
  raise 'File not found: ' + path_to_archive.to_s unless wait_file_to_download(path_to_archive)
@@ -57,6 +67,10 @@ module OnlyofficeFileHelper
57
67
  end
58
68
  end
59
69
 
70
+ # Save string to file
71
+ # @param string [String] string to save
72
+ # @param file_name [String] file to save
73
+ # @return [Void]
60
74
  def output_string_to_file(string, file_name)
61
75
  File.open(file_name, 'a+') do |f1|
62
76
  f1.write(string)
@@ -3,6 +3,9 @@
3
3
  module OnlyofficeFileHelper
4
4
  # Methods used to create something
5
5
  module CreateMethods
6
+ # Gracefully create folder. Do not fail if already exists
7
+ # @param path [String] path to folder
8
+ # @return [Void]
6
9
  def create_folder(path)
7
10
  FileUtils.mkdir_p(path) unless File.directory?(path)
8
11
  rescue Errno::EEXIST
@@ -3,10 +3,16 @@
3
3
  module OnlyofficeFileHelper
4
4
  # Methods used to work with directories
5
5
  module DirectoryMethods
6
+ # Delete directory only if it exists
7
+ # @param path [String] directory to delete
8
+ # @return [Void]
6
9
  def delete_directory(path)
7
10
  FileUtils.rm_rf(path) if Dir.exist?(path)
8
11
  end
9
12
 
13
+ # List of files in directory as array
14
+ # @param path [String] path to directory
15
+ # @return [Array<String>] list of all files
10
16
  def directory_hash(path)
11
17
  files = []
12
18
  Dir.foreach(path).sort.each do |entry|
@@ -19,6 +25,10 @@ module OnlyofficeFileHelper
19
25
  files
20
26
  end
21
27
 
28
+ # List all files in directory
29
+ # @param directory [String] path to directory
30
+ # @param extension [String] filter extension
31
+ # @return [Array<String>] list of all files
22
32
  def list_file_in_directory(directory, extension = nil)
23
33
  paths = []
24
34
  Find.find(directory) do |path|
@@ -8,27 +8,38 @@ module OnlyofficeFileHelper
8
8
  class LinuxHelper
9
9
  extend XdotoolHelper
10
10
 
11
+ # Download file by link using
12
+ # @param link [String] url to download
13
+ # @param full_name_file [String] path to save file
14
+ # @return [Void]
11
15
  def self.download_file(link, full_name_file)
12
16
  `wget -O #{full_name_file} #{link}`
13
17
  end
14
18
 
19
+ # Kill All process with specified pattern name
20
+ # @param process [String] names of process
21
+ # @return [Void]
15
22
  def self.kill_all(process)
16
23
  OnlyofficeLoggerHelper.log("killall -9 #{process} 2>&1")
17
24
  `killall -9 #{process} 2>&1`
18
25
  end
19
26
 
27
+ # Just kill all known browsers
28
+ # @return [Void]
20
29
  def self.kill_all_browsers
21
30
  kill_all('firefox')
22
31
  kill_all('chrome')
23
32
  kill_all('opera')
24
33
  end
25
34
 
35
+ # @return [String] current user name
26
36
  def self.user_name
27
37
  `id -u -n`
28
38
  end
29
39
 
30
40
  singleton_class.send(:alias_method, :get_user_name, :user_name)
31
41
 
42
+ # @return [String] current computer name
32
43
  def self.computer_name
33
44
  computer_name = Socket.gethostname
34
45
  OnlyofficeLoggerHelper.log("`LinuxHelper.get_computer_name` # #{computer_name}")
@@ -37,6 +48,7 @@ module OnlyofficeFileHelper
37
48
 
38
49
  singleton_class.send(:alias_method, :get_computer_name, :computer_name)
39
50
 
51
+ # @return [String] content of clipboard
40
52
  def self.clipboard_content
41
53
  `xclip -o`
42
54
  end
@@ -50,6 +62,7 @@ module OnlyofficeFileHelper
50
62
  `xdg-user-dir #{name.to_s.upcase}`.strip
51
63
  end
52
64
 
65
+ # @return [String] external ip of system
53
66
  def self.my_external_ip
54
67
  `curl "http://myexternalip.com/raw"`.chomp
55
68
  end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OnlyofficeFileHelper
4
+ # @return [String] name of gem
5
+ NAME = 'onlyoffice_file_helper'
6
+ end
@@ -3,6 +3,9 @@
3
3
  module OnlyofficeFileHelper
4
4
  # Methods used to read something
5
5
  module ReadMethods
6
+ # Read file content to string
7
+ # @param file_name [String] file to read
8
+ # @return [String] result of read
6
9
  def read_file_to_string(file_name)
7
10
  result_string = ''
8
11
  raise 'File not found: ' + file_name.to_s unless File.exist?(file_name)
@@ -15,6 +18,9 @@ module OnlyofficeFileHelper
15
18
  result_string
16
19
  end
17
20
 
21
+ # Read file content to array, split by newline
22
+ # @param file_name [String] path to file
23
+ # @return [Array<String>] result of read
18
24
  def read_array_from_file(file_name)
19
25
  result_array = []
20
26
  return [] unless File.exist?(file_name)
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OnlyofficeFileHelper
4
+ # Class for method for ruby
5
+ class RubyHelper
6
+ # @return [True, False] is current processs run in debug
7
+ def self.debug?
8
+ ENV['RUBYLIB'].to_s.include?('ruby-debug')
9
+ end
10
+ end
11
+ end
@@ -4,10 +4,16 @@ module OnlyofficeFileHelper
4
4
  # Helper for Strings
5
5
  class StringHelper
6
6
  class << self
7
+ # Random string with specific length
8
+ # @param length_string [Integer] length of string
9
+ # @return [String] string with length
7
10
  def generate_random_string(length_string = 32)
8
11
  (0...length_string).map { (('a'..'z').to_a + ('A'..'Z').to_a)[rand(52)] }.join
9
12
  end
10
13
 
14
+ # Generate random number with prefix
15
+ # @param value [String, Integer] prefix to generate
16
+ # @return [String] result of random number
11
17
  def generate_random_number(value = nil)
12
18
  "#{value}: #{Time.now.nsec}"
13
19
  end
@@ -17,7 +23,10 @@ module OnlyofficeFileHelper
17
23
  # @param [String] first_element 1'st element to compare
18
24
  # @param [String] second_element 2'st element to compare
19
25
  # @return [String] String with result of comparison
20
- def get_result_string_of_comparison(compare_parameter, first_element, second_element, accuracy = 0.01)
26
+ def get_result_string_of_comparison(compare_parameter,
27
+ first_element,
28
+ second_element,
29
+ accuracy = 0.01)
21
30
  if first_element.is_a?(Float) && second_element.is_a?(Float)
22
31
  difference = (first_element - second_element).abs
23
32
  difference >= accuracy ? "Difference between parameters in #{compare_parameter} is #{difference}" : ''
@@ -28,6 +37,9 @@ module OnlyofficeFileHelper
28
37
  end
29
38
  end
30
39
 
40
+ # Convert string to boolean value
41
+ # @param string [String] to convert
42
+ # @return [True, False]
31
43
  def to_bool(string)
32
44
  str = string.to_s
33
45
  if str.casecmp('false').zero?
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OnlyofficeFileHelper
4
- VERSION = '0.2.0'
4
+ # @return [String] version of gem
5
+ VERSION = '0.3.0'
5
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onlyoffice_file_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ONLYOFFICE
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-03-06 00:00:00.000000000 Z
12
+ date: 2020-04-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: onlyoffice_logger_helper
@@ -45,6 +45,20 @@ dependencies:
45
45
  - - "<"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '3'
48
+ - !ruby/object:Gem::Dependency
49
+ name: rake
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '13.0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '13.0'
48
62
  description: ONLYOFFICE Helper Gem for File operation. Used in QA
49
63
  email:
50
64
  - shockwavenn@gmail.com
@@ -52,19 +66,25 @@ executables: []
52
66
  extensions: []
53
67
  extra_rdoc_files: []
54
68
  files:
55
- - README.md
56
69
  - lib/onlyoffice_file_helper.rb
57
70
  - lib/onlyoffice_file_helper/create_methods.rb
58
71
  - lib/onlyoffice_file_helper/directory_methods.rb
59
72
  - lib/onlyoffice_file_helper/linux_helper.rb
60
73
  - lib/onlyoffice_file_helper/linux_helper/xdotool_helper.rb
74
+ - lib/onlyoffice_file_helper/name.rb
61
75
  - lib/onlyoffice_file_helper/read_methods.rb
76
+ - lib/onlyoffice_file_helper/ruby_helper.rb
62
77
  - lib/onlyoffice_file_helper/string_helper.rb
63
78
  - lib/onlyoffice_file_helper/version.rb
64
79
  homepage: https://github.com/onlyoffice-testing-robot/onlyoffice_file_helper
65
80
  licenses:
66
81
  - AGPL-3.0
67
- metadata: {}
82
+ metadata:
83
+ bug_tracker_uri: https://github.com/onlyoffice-testing-robot/onlyoffice_file_helper/issues
84
+ changelog_uri: https://github.com/onlyoffice-testing-robot/onlyoffice_file_helper/blob/master/CHANGELOG.md
85
+ documentation_uri: https://www.rubydoc.info/gems/onlyoffice_file_helper
86
+ homepage_uri: https://github.com/onlyoffice-testing-robot/onlyoffice_file_helper
87
+ source_code_uri: https://github.com/onlyoffice-testing-robot/onlyoffice_file_helper
68
88
  post_install_message:
69
89
  rdoc_options: []
70
90
  require_paths:
@@ -80,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
100
  - !ruby/object:Gem::Version
81
101
  version: '0'
82
102
  requirements: []
83
- rubygems_version: 3.0.6
103
+ rubygems_version: 3.1.2
84
104
  signing_key:
85
105
  specification_version: 4
86
106
  summary: ONLYOFFICE Helper Gem for File operation
data/README.md DELETED
@@ -1,39 +0,0 @@
1
- # OnlyofficeFileHelper
2
-
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/onlyoffice_file_helper`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'onlyoffice_file_helper'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install onlyoffice_file_helper
22
-
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
-
33
- ## Contributing
34
-
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/onlyoffice_file_helper. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
-
37
- ## Code of Conduct
38
-
39
- Everyone interacting in the OnlyofficeFileHelper project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/onlyoffice_file_helper/blob/master/CODE_OF_CONDUCT.md).