sugar_utils 0.5.0 → 0.6.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
  SHA1:
3
- metadata.gz: 8f9d52c1492ed959f2b33c945732bf36188e6fc1
4
- data.tar.gz: b68e7a45954e73eeac4cfe214c5aec54e4602fd2
3
+ metadata.gz: b7c411a9357b3eaec0a69621f5d90158e73cb529
4
+ data.tar.gz: 89c32ae0e47afda5f96e893497779a9c50faf183
5
5
  SHA512:
6
- metadata.gz: cdf2c594969a6c7c0b5279032c18a40b4ce4b6c2b27e86cd814e4f7aa15ded81d661d63890795c5414e27907eb2a4d95c903a22ce3f76803b2f63b41e55bd60b
7
- data.tar.gz: 5434657b56c88ee11296ff25d9ee00e43207050da6345f6df4e34717edcb8fbe7bb7dcc492c1cad326cd85efd9fae02f37fe4fd71a7dfffe7162ed9930b5b96e
6
+ metadata.gz: 5dd4e7190bacaf4eb839da4cc06395c0533b5f21e77e548d634466eb6f2c1aa17e6d38c5578850bbc2e2c93a678ec3626e65b8de2e68e5ae8ebf05866d8e4185
7
+ data.tar.gz: baf241f695e61396cfd8eaff4ccedca6a8e2c4771a9668d39930fa1c967e0d2bc3a7b055cf167bfa4820d5a6b86ed1b1fb3a132bfa56675b269e6897acdbcabd
@@ -1,3 +1,8 @@
1
+ require: rubocop-rspec
2
+
3
+ AllCops:
4
+ TargetRubyVersion: 2.2
5
+
1
6
  Documentation:
2
7
  Enabled: false
3
8
 
@@ -6,8 +11,19 @@ Metrics/LineLength:
6
11
  Include:
7
12
  - 'spec/**/*'
8
13
 
14
+ RSpec/EmptyExampleGroup:
15
+ Enabled: false
16
+
9
17
  # Because of the way that blocks are used in RSpecs can end up being long when
10
18
  # example groups are nested or many examples are checked.
19
+ # A similar pattern exists in the DSL for gemspec files.
11
20
  Metrics/BlockLength:
12
21
  Exclude:
22
+ - '*.gemspec'
13
23
  - 'spec/**/*'
24
+
25
+ RSpec/ExpectInHook:
26
+ Enabled: false
27
+
28
+ RSpec/MessageSpies:
29
+ Enabled: false
@@ -1,22 +1,39 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0
4
- - 2.1
5
3
  - 2.2
6
4
  - 2.3
7
- - 2.4
8
- - 2.5
5
+ - 2.4.5
6
+ - 2.5.4
7
+ - 2.6.2
9
8
  - ruby-head
9
+ - jruby
10
10
  matrix:
11
- allow_failures:
12
- - rvm: ruby-head
13
- - rvm: 2.0
11
+ exclude:
12
+ - rvm: jruby
14
13
  os: osx
15
- - rvm: 2.4
14
+ - rvm: ruby-head
16
15
  os: osx
16
+ allow_failures:
17
+ - rvm: ruby-head
18
+ - rvm: jruby
17
19
  os:
18
20
  - linux
19
21
  - osx
20
22
  sudo: false
21
- after_success:
22
- - bundle exec codeclimate-test-reporter
23
+ cache:
24
+ bundler: true
25
+ before_script:
26
+ - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-darwin-amd64 > ./cc-test-reporter ; fi
27
+ - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter ; fi
28
+ - chmod +x ./cc-test-reporter
29
+ - ./cc-test-reporter before-build
30
+ after_script:
31
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
32
+
33
+ # HACK: Continue to use bundler <2 because of Ruby v2.2 support. Once the
34
+ # lowest dependency is Ruby v2.3 we can consider upgrading to Bundler 2.x.
35
+ # @see https://docs.travis-ci.com/user/languages/ruby/#bundler-20
36
+ before_install:
37
+ - gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
38
+ - gem install bundler -v '< 2'
39
+
@@ -6,6 +6,22 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.6.0] - 2019-05-31
10
+ ### Added
11
+ - SugarUtils::File.append, which is explicitly for appending to a file. It will
12
+ also create a new file if it does not yet exist
13
+ - SugarUtils::scrub_encoding, which is used for cleaning badly encoded
14
+ characters out of a string
15
+ - SugarUtils::File.change_access, a wrapper for changing ownership and
16
+ permissions of a file
17
+ - SugarUtils::File.atomic_write, to atomically write a file
18
+ ### Removed
19
+ - append support in SugarUtils::File.write (could have been specified by { mode: 'a })
20
+ ### Changed
21
+ - :mode and :perm are now aliases for setting permissions on files in all the
22
+ related methods (i.e., .write, .write_json, .touch, .append)
23
+ - convert SugarUtils::File.write_json to use .atomic_write
24
+
9
25
  ## [0.5.0] - 2018-05-01
10
26
  ### Changed
11
27
  - bring back :perm as option to set the permissions in SugarUtils::File.write and SugarUtils::File.touch methods
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # sugar_utils
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/sugar_utils.svg)](http://badge.fury.io/rb/sugar_utils)
4
- [![Dependency Status](https://gemnasium.com/sugarcrm/sugar_utils.svg)](https://gemnasium.com/sugarcrm/sugar_utils)
5
4
  [![Build Status](https://travis-ci.org/sugarcrm/sugar_utils.svg?branch=master)](https://travis-ci.org/sugarcrm/sugar_utils)
6
5
  [![Code Climate](https://codeclimate.com/github/sugarcrm/sugar_utils/badges/gpa.svg)](https://codeclimate.com/github/sugarcrm/sugar_utils)
7
6
  [![Test Coverage](https://codeclimate.com/github/sugarcrm/sugar_utils/badges/coverage.svg)](https://codeclimate.com/github/sugarcrm/sugar_utils/coverage)
@@ -14,12 +13,16 @@ These methods are included:
14
13
 
15
14
  * SugarUtils.ensure_boolean
16
15
  * SugarUtils.ensure_integer
16
+ * SugarUtils.scrub_encoding
17
17
  * SugarUtils::File.flock_shared
18
18
  * SugarUtils::File.flock_exclusive
19
+ * SugarUtils::File.change_access
19
20
  * SugarUtils::File.read
20
21
  * SugarUtils::File.write
22
+ * SugarUtils::File.atomic_write
21
23
  * SugarUtils::File.read_json
22
24
  * SugarUtils::File.write_json
25
+ * SugarUtils::File.append
23
26
 
24
27
  These methods will probably be included in the future:
25
28
 
@@ -59,6 +62,12 @@ $ gem install sugar_utils
59
62
 
60
63
  See [CONTRIBUTING](CONTRIBUTING.md) for how you can contribute changes back into this project.
61
64
 
62
- ## Acknowledgments
65
+ ## Contributors
63
66
 
64
- Copyright 2016 [SugarCRM Inc.](http://sugarcrm.com), released under the Apache2 License.
67
+ * [Andrew Sullivan Cant](https://github.com/acant)
68
+ * [Robert Lockstone](https://github.com/lockstone)
69
+ * [Vadim Kazakov](https://github.com/yads)
70
+
71
+ ## Acknowledgements
72
+
73
+ Copyright 2019 [SugarCRM Inc.](http://sugarcrm.com), released under the Apache2 License.
data/Rakefile CHANGED
@@ -1,18 +1,47 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  require 'bundler/gem_tasks'
5
4
  require 'rspec/core/rake_task'
5
+ require 'cucumber'
6
+ require 'cucumber/rake/task'
6
7
  require 'rubocop/rake_task'
8
+ require 'bundler/audit/task'
7
9
  require 'yard'
8
10
  require 'yardstick/rake/measurement'
9
- require 'fileutils'
11
+ require 'pathname'
12
+ require 'license_finder'
13
+ require 'English'
10
14
 
11
- RSpec::Core::RakeTask.new(:spec)
15
+ RSpec::Core::RakeTask.new(:spec) do |task|
16
+ # task.rspec_opts = '--warnings'
17
+ end
18
+
19
+ Cucumber::Rake::Task.new(:features) do |task|
20
+ end
12
21
 
13
22
  RuboCop::RakeTask.new(:rubocop) do |task|
14
- FileUtils.mkdir_p('tmp')
15
- task.options = %w[--format progress --format simple --out tmp/rubocop.txt]
23
+ rubocop_report_pathname =
24
+ Pathname(Rake.application.original_dir).join('tmp', 'rubocop.txt')
25
+ rubocop_report_pathname.dirname.mkpath
26
+ task.options =
27
+ %w[
28
+ --display-cop-names
29
+ --extra-details
30
+ --display-style-guide
31
+ --fail-level error
32
+ --format progress
33
+ --format simple
34
+ --out
35
+ ].push(rubocop_report_pathname.to_s)
36
+ end
37
+
38
+ Bundler::Audit::Task.new
39
+
40
+ desc 'Check dependency licenses'
41
+ task :license_finder do
42
+ puts `license_finder --quiet --format text`
43
+
44
+ abort('LicenseFinder failed') unless $CHILD_STATUS.success?
16
45
  end
17
46
 
18
47
  YARD::Rake::YardocTask.new do |t|
@@ -24,6 +53,4 @@ Yardstick::Rake::Measurement.new(:yardstick_measure) do |measurement|
24
53
  measurement.output = 'tmp/yard_coverage.txt'
25
54
  end
26
55
 
27
- task quality: %i[rubocop yardstick_measure]
28
-
29
- task default: %i[spec]
56
+ task default: %i[spec features rubocop yardstick_measure bundle:audit license_finder]
@@ -0,0 +1,46 @@
1
+ Feature: Append to a file
2
+
3
+ Scenario: Append a missing file
4
+ When I run the following Ruby code:
5
+ """ruby
6
+ require 'sugar_utils'
7
+ SugarUtils::File.append('dir/test', 'foobar')
8
+ """
9
+ Then the file named "dir/test" should contain exactly:
10
+ """
11
+ foobar
12
+ """
13
+
14
+ Scenario: Append an existing file
15
+ Given a file named "dir/test" with "foobar"
16
+ When I run the following Ruby code:
17
+ """ruby
18
+ require 'sugar_utils'
19
+ SugarUtils::File.append('dir/test', 'deadbeef')
20
+ """
21
+ Then the file named "dir/test" should contain exactly:
22
+ """
23
+ foobardeadbeef
24
+ """
25
+
26
+ # TODO: Fix the owner/group setting check
27
+ Scenario: Append a file and reset its permissions
28
+ Given a file named "dir/test" with "foobar"
29
+ When I run the following Ruby code:
30
+ """ruby
31
+ require 'sugar_utils'
32
+ SugarUtils::File.append(
33
+ 'dir/test',
34
+ 'deadbeef',
35
+ # owner: 'nobody',
36
+ # group: 'nogroup',
37
+ mode: 0o777
38
+ )
39
+ """
40
+ Then the file named "dir/test" should contain exactly:
41
+ """
42
+ foobardeadbeef
43
+ """
44
+ And the file named "dir/test" should have permissions "777"
45
+ # And the file named "dir/test" should have owner "nobody"
46
+ # And the file named "dir/test" should have group "nogroup"
@@ -0,0 +1,46 @@
1
+ Feature: Write to a file atomically
2
+
3
+ Scenario: Write a file atomically
4
+ When I run the following Ruby code:
5
+ """ruby
6
+ require 'sugar_utils'
7
+ puts SugarUtils::File.atomic_write('dir/test', 'foobar')
8
+ """
9
+ Then the file named "dir/test" should contain exactly:
10
+ """
11
+ foobar
12
+ """
13
+
14
+ Scenario: Overwrite a file atomically
15
+ Given a file named "dir/test" with "deadbeef"
16
+ When I run the following Ruby code:
17
+ """ruby
18
+ require 'sugar_utils'
19
+ puts SugarUtils::File.atomic_write('dir/test', 'foobar')
20
+ """
21
+ Then the file named "dir/test" should contain exactly:
22
+ """
23
+ foobar
24
+ """
25
+
26
+ # TODO: Fix the owner/group setting check
27
+ Scenario: Overwrite a file and reset its permissions atomically
28
+ Given a file named "dir/test" with "deadbeef"
29
+ When I run the following Ruby code:
30
+ """ruby
31
+ require 'sugar_utils'
32
+ puts SugarUtils::File.atomic_write(
33
+ 'dir/test',
34
+ 'foobar',
35
+ # owner: 'nobody',
36
+ # group: 'nogroup',
37
+ mode: 0o777
38
+ )
39
+ """
40
+ Then the file named "dir/test" should contain exactly:
41
+ """
42
+ foobar
43
+ """
44
+ And the file named "dir/test" should have permissions "777"
45
+ # And the file named "dir/test" should have owner "nobody"
46
+ # And the file named "dir/test" should have group "nogroup"
@@ -0,0 +1,27 @@
1
+ Feature: Change a files ownership and permissions
2
+
3
+ # TODO: Fix the owner/group setting check. I need to figure out how to execute
4
+ # these scenarios correctly across various environments.
5
+
6
+ Scenario: All the values are skipped
7
+ Given a file named "test" with "foobar"
8
+ When I run the following Ruby code:
9
+ """ruby
10
+ require 'sugar_utils'
11
+ SugarUtils::File.change_access('test', nil, nil, nil)
12
+ """
13
+ # Then the file named "test" should have permissions "644"
14
+ # And the file named "test" should have owner "nobody"
15
+ # And the file named "test" should have group "nogroup"
16
+
17
+ Scenario: All the values are set
18
+ Given a file named "test" with "foobar"
19
+ When I run the following Ruby code:
20
+ """ruby
21
+ require 'sugar_utils'
22
+ # SugarUtils::File.change_access('test', 'nobody', 'nogroup', 0o777)
23
+ SugarUtils::File.change_access('test', nil, nil, 0o777)
24
+ """
25
+ Then the file named "test" should have permissions "777"
26
+ # And the file named "test" should have owner "nobody"
27
+ # And the file named "test" should have group "nogroup"
@@ -0,0 +1,34 @@
1
+
2
+ Feature: Ensure the specified value is a boolean
3
+
4
+ Scenario: nil is false
5
+ When I run the following Ruby code:
6
+ """ruby
7
+ require 'sugar_utils'
8
+ puts SugarUtils.ensure_boolean(nil)
9
+ """
10
+ Then the output should contain "false"
11
+
12
+ Scenario: false is false
13
+ When I run the following Ruby code:
14
+ """ruby
15
+ require 'sugar_utils'
16
+ puts SugarUtils.ensure_boolean(false)
17
+ """
18
+ Then the output should contain "false"
19
+
20
+ Scenario: String of 'false' is false
21
+ When I run the following Ruby code:
22
+ """ruby
23
+ require 'sugar_utils'
24
+ puts SugarUtils.ensure_boolean('false')
25
+ """
26
+ Then the output should contain "false"
27
+
28
+ Scenario: Any other value is true
29
+ When I run the following Ruby code:
30
+ """ruby
31
+ require 'sugar_utils'
32
+ puts SugarUtils.ensure_boolean('value')
33
+ """
34
+ Then the output should contain "true"
@@ -0,0 +1,19 @@
1
+ Feature: Ensure the specified value is an integer
2
+
3
+ Scenario: Convert Floats to Integers
4
+ When I run the following Ruby code:
5
+ """ruby
6
+ require 'sugar_utils'
7
+ puts SugarUtils.ensure_integer(123.456)
8
+ """
9
+ Then the output should contain "123"
10
+
11
+ Scenario: Convert Strings of Integers to Integers
12
+ When I run the following Ruby code:
13
+ """ruby
14
+ require 'sugar_utils'
15
+ puts SugarUtils.ensure_integer('123.456')
16
+ """
17
+ Then the output should contain "123"
18
+
19
+
@@ -0,0 +1,26 @@
1
+ # TODO: Fill in this feature
2
+ Feature: Operate locks on files
3
+
4
+ Scenario: Shared lock
5
+ Given a file named "test" with "foobar"
6
+ When I run the following Ruby code:
7
+ """ruby
8
+ require 'sugar_utils'
9
+ File.open('test') do |file|
10
+ SugarUtils::File.flock_shared(file)
11
+ puts file.read
12
+ end
13
+ """
14
+ Then the file named "test" should contain "foobar"
15
+
16
+ Scenario: Exclusive lock
17
+ Given a file named "test" with "foobar"
18
+ When I run the following Ruby code:
19
+ """ruby
20
+ require 'sugar_utils'
21
+ File.open('test') do |file|
22
+ SugarUtils::File.flock_exclusive(file)
23
+ puts file.read
24
+ end
25
+ """
26
+ Then the file named "test" should contain "foobar"
@@ -0,0 +1,30 @@
1
+ Feature: Read a file
2
+
3
+ Scenario: Read a missing file with a default value
4
+ When I run the following Ruby code:
5
+ """ruby
6
+ require 'sugar_utils'
7
+ puts SugarUtils::File.read(
8
+ 'test', value_on_missing: 'missing', raise_on_missing: false
9
+ )
10
+ """
11
+ Then the output should contain "missing"
12
+
13
+ Scenario: Read an existing file
14
+ Given a file named "test" with "foobar"
15
+ When I run the following Ruby code:
16
+ """ruby
17
+ require 'sugar_utils'
18
+ puts SugarUtils::File.read('test')
19
+ """
20
+ Then the output should contain "foobar"
21
+
22
+ Scenario: Read an existing file and scurb encoding errors
23
+ Given a file named "test" with "test"
24
+ When I run the following Ruby code:
25
+ """ruby
26
+ require 'sugar_utils'
27
+ File.write('test', %(foo\\x92bar\\x93))
28
+ puts SugarUtils::File.read('test', scrub_encoding: true)
29
+ """
30
+ Then the output should contain "foobar"