tcravit_ruby_lib 0.2.7 → 0.2.8

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: 10035a5eb75e32c6e501a23706115d956173a4ad0c1ef200fd788321b903c51f
4
- data.tar.gz: '0428138258d21e3df798abb6f4966d1e8910f5c5158818e3bf04ea95a830075c'
3
+ metadata.gz: 99beb5b023dc1d79ac40040e472823a0c930a60c9675fc7915efa3fd9be6c4b5
4
+ data.tar.gz: 5c663f58eb23d5530476bbdf3d7551f4fe36b01649f5063047b55f2f4acc2e9b
5
5
  SHA512:
6
- metadata.gz: f87829a1df51e1bed94ee6b8caf23db45994567a8a759a2adf7b56cec1001f38e76bc51935a03d257be3252bb18128d1015ced8a957b46673155f66f9ebbc55e
7
- data.tar.gz: e9ce8fcc9249239b74a5e4375ed8c05a2c2ec2a0871ced5f2a953ca44158e465da66bf56cbc5abe064ec7f8f732b1193e27af93c86227d506399ebe0822c24e2
6
+ metadata.gz: f80ddab2f052a5042fd3ee8be67d00d71010611e7ca4e3b04e686d8fad808f886ff9a8be0f6e1fe4f8bcc59260ff16a4a687505668743d3db96529c7d427761d
7
+ data.tar.gz: 41012afc7344c3fbf42fdb1d8d3d0e6ddf751b23da64e7c431a81fd5103dfd24dda7c9b4f7d4a778c1995a08b5a2eed2afe6a3941dad851c24321a2cf19261c4
@@ -24,8 +24,8 @@ $:.unshift File.dirname(__FILE__)
24
24
  # Make sure we load the version definitions first
25
25
  require "tcravit_ruby_lib/version"
26
26
 
27
- Dir[File.join(File.dirname(__FILE__), "tcravit_ruby_lib", "*.rb")].each do |f|
28
- require File.join("tcravit_ruby_lib", File.basename(f)) unless File.basename(f) == "version.rb"
27
+ Dir[File.join(File.dirname(__FILE__), "tcravit_ruby_lib", "*.rb")].reject { |x| File.basename(x) == "version.rb" }.each do |f|
28
+ require File.join("tcravit_ruby_lib", File.basename(f))
29
29
  end
30
30
 
31
31
  module TcravitRubyLib # :nodoc:
@@ -20,8 +20,50 @@
20
20
  # limitations under the License.
21
21
  ############################################################################
22
22
 
23
- module TcravitRubyLib #-nodoc-#
24
- def self.Banner(opts={})
23
+ module TcravitRubyLib #-nodoc-#
24
+
25
+ extend self
26
+
27
+ ##
28
+ # Generate an app startup banner for a command-line application.
29
+ #
30
+ # == Banner Formatting
31
+ #
32
+ # The app banner will be framed with asterisks. By default, it will be 76
33
+ # characters long, though this can be overridden by passing in a value for
34
+ # +line_length+.
35
+ #
36
+ # If a +description+ is included, the first text line of the banner will
37
+ # take the form "name: description"; otherwise, just the name will be
38
+ # output. This line will be centered, with whitespace added to the ends to
39
+ # make the asterisks line up. Otherwise, just the app name will be output.
40
+ #
41
+ # If any of +version+, +date+, and/or +author+ are supplied, these will be
42
+ # joined (in that order) by commas, and a second centered line of text
43
+ # containing those components will be output. If none are supplied, no
44
+ # second line will be output.
45
+ #
46
+ # == Arguments
47
+ #
48
+ # For flexibility, parameters are all passed in a hash. The method accepts
49
+ # the following options:
50
+ #
51
+ # * `:name` - The name of the application. Required.
52
+ # * `:description` - A brief description of the application. Optional.
53
+ # * `:version`
54
+ # * `:date`
55
+ # * `:author`
56
+ # * `:line_length`
57
+ #
58
+ # The only required option is +name+, and an ArgumentError will be raised
59
+ # if it is not supplied. All other options are optional, and the method
60
+ # will simply use whichever ones are supplied to generate the banner.
61
+ #
62
+ # For examples, see the RSpec tests for this method.
63
+ #
64
+ # @param opts [Hash] A hash of options.
65
+ # @return [String] The app banner, ready to print out
66
+ def Banner(opts={})
25
67
  raise ArgumentError, "Name not provided" unless opts.keys.include?("name".to_sym)
26
68
 
27
69
  line_length = 76
@@ -55,7 +97,8 @@ module TcravitRubyLib #-nodoc-#
55
97
  return lines.join("\n")
56
98
  end
57
99
 
58
- def self.asterisk_pad(data, length=76)
100
+ private
101
+ def asterisk_pad(data, length=76)
59
102
  buf = "* " + (" " * (((length-4) - data.length) / 2)) + data
60
103
  buf = buf + (" " * ((length-2) - buf.length)) + " *"
61
104
  return buf
@@ -21,7 +21,8 @@
21
21
 
22
22
  module TcravitRubyLib #:nodoc:
23
23
 
24
- # Simple and Flexible Configuration Data Storage.
24
+ ##
25
+ ## Simple and Flexible Configuration Data Storage.
25
26
  #
26
27
  # AppConfig provides a simple facility for storing configuration data in
27
28
  # an application. It does this using metaprogramming techniques to define
@@ -44,7 +45,28 @@ module TcravitRubyLib #:nodoc:
44
45
 
45
46
  module AppConfig
46
47
  extend self
47
-
48
+
49
+ ##
50
+ # Configure the settings.
51
+ #
52
+ # +configure+ accepts a block which is evaluated by `instance_eval`.
53
+ # Method calls inside this block are turned into app settings via
54
+ # {#method_missing}, which dynamically creates getters and setters
55
+ # for the provided values.
56
+ #
57
+ # As a side effect, this means you can't create app settings whose
58
+ # name is the same as a ruby reserved word or a method defined by a
59
+ # ruby `Object`, because those calls don't trigger {#method_missing}
60
+ # to execute. In practice, this shouldn't be a huge limitation, but
61
+ # it's worth being aware of.
62
+ #
63
+ # Configuration setting names must begin with an uppercase letter,
64
+ # lowercase letter, or digit. Dashes and underscores are permitted
65
+ # after the initial character.
66
+ #
67
+ # @param block [Block] The configuration block.
68
+ # @return Nothing, but stores the configuration values provided
69
+ # inside the block.
48
70
  def configure(&block)
49
71
  @definitions ||= Hash.new
50
72
 
@@ -54,14 +76,27 @@ module TcravitRubyLib #:nodoc:
54
76
  instance_eval &block
55
77
  @in_config = false
56
78
  end
57
-
79
+
80
+ #@
81
+ # Remove a previously defined configuration value.
82
+ #
83
+ # {#remove} can be passed the name of the configuration setting as
84
+ # a string or a symbol. If the requested setting exists, its value
85
+ # will be discarded, and the getter and setter methods will be
86
+ # undefined. If the requested setting does not exist, no action is
87
+ # taken and no exceptions are raised.
88
+ #
89
+ # @param key [String] The configuration setting to remove. A symbol
90
+ # can also be provided for the +key+.
91
+ # @return Nothing.
58
92
  def remove!(key)
59
93
  the_sym = key.to_sym
60
- @definitions.delete(the_sym)
61
- send :undef_method, the_sym
62
- send :undef_method, "#{the_sym.to_s}=".to_sym
94
+ @definitions.delete(the_sym) if @definitions.include?(the_sym)
95
+ send :undef_method, the_sym if self.respond_to?(the_sym)
96
+ send :undef_method, "#{the_sym.to_s}=".to_sym if self.respond_to?("#{the_sym.to_s}=".to_sym)
63
97
  end
64
-
98
+
99
+ #-nodoc-#
65
100
  def method_missing(methname, *args)
66
101
  if (methname.to_s =~ /^([A-Za-z0-9][A-Za-z0-9\-\_]+)$/)
67
102
  if @in_config
@@ -24,7 +24,8 @@ require 'pathname'
24
24
 
25
25
  module TcravitRubyLib #:nodoc:
26
26
 
27
- # Utilities for locating a configuration directory within a tree.
27
+ ##
28
+ # jUtilities for locating a configuration directory within a tree.
28
29
  #
29
30
  # Unix utilities such as +git+ will look for the .git directory in a
30
31
  # project by starting with the current directory and traversing upward
@@ -33,13 +34,6 @@ module TcravitRubyLib #:nodoc:
33
34
  #
34
35
  # This module, inspired by a post on Practicing Ruby, implements that
35
36
  # kind of traversal for Ruby applications.
36
- #
37
- # Author:: Tammy Cravit (mailto:tammy@tammycravit.com)
38
- # Copyright:: Copyright (c) 2011, Tammy Cravit. All rights reserved.
39
- # License:: This program is free software: you can redistribute it and/or modify
40
- # it under the terms of the GNU General Public License as published by
41
- # the Free Software Foundation, either version 3 of the License, or
42
- # (at your option) any later version.
43
37
  module ConfigSearcher
44
38
 
45
39
  # Locate a configuration folder by starting in the specified directory
@@ -40,6 +40,8 @@ module TcravitRubyLib #:nodoc:
40
40
  # end
41
41
 
42
42
  module Configurable
43
+
44
+ # +nodoc+
43
45
  def self.with(*attrs)
44
46
  not_provided = Object.new
45
47
  config_class = Class.new do
@@ -22,6 +22,11 @@
22
22
  require 'rake'
23
23
 
24
24
  module TcravitRubyLib
25
+ ##
26
+ # Load and install rake tasks defined within the TcravitRubyLib library.
27
+ #
28
+ # This module is designed to be require'd by a Rakefile, and will load and
29
+ # install all of the Rake tasks contained within the library.
25
30
  class RakeTasks
26
31
  include Rake::DSL if defined?(Rake::DSL)
27
32
 
@@ -19,16 +19,9 @@
19
19
  ############################################################################
20
20
 
21
21
  def find_version_file
22
- curr_dir = File.dirname(__FILE__)
23
- while File.exist?(File.join(curr_dir, "Rakefile")) == false
24
- if curr_dir == "/"
25
- return nil
26
- else
27
- curr_dir = File.expand_path(curr_dir + "/..")
28
- end
29
- end
30
- if File.directory?(File.join(curr_dir)) then
31
- ver_file = Dir["#{curr_dir}/**/version.rb"]
22
+ rake_dir = Rake.original_dir
23
+ if File.directory?(rake_dir) then
24
+ ver_file = Dir["#{rake_dir}/**/version.rb"]
32
25
  if ver_file.nil?
33
26
  return nil
34
27
  else
@@ -82,9 +75,15 @@ def update_gem_version_part(index=2, test_mode=false)
82
75
 
83
76
  vd = TcravitRubyLib::VERSION_DATA
84
77
  vd[index] = vd[index] + 1
78
+ if (index < 2)
79
+ vd[2] = 0
80
+ end
81
+ if (index == 0)
82
+ vd[1] = 0
83
+ end
85
84
 
86
85
  if test_mode then
87
- write_output_to("/tmp/bump_ver.out", create_file_contents(module_name, vd))
86
+ write_output_to("/tmp/bump_ver_#{positions[index]}.out", create_file_contents(module_name, vd))
88
87
  else
89
88
  write_output_to(version_file, create_file_contents(module_name, vd))
90
89
  end
@@ -99,7 +98,7 @@ def set_gem_version(major, minor, build, test_mode=false)
99
98
  vd = [major, minor, build]
100
99
 
101
100
  if test_mode then
102
- write_output_to("/tmp/bump_ver.out", create_file_contents(module_name, vd))
101
+ write_output_to("/tmp/bump_ver_set.out", create_file_contents(module_name, vd))
103
102
  else
104
103
  write_output_to(version_file, create_file_contents(module_name, vd))
105
104
  end
@@ -22,9 +22,23 @@
22
22
  require 'simple-password-gen'
23
23
 
24
24
  module TcravitRubyLib
25
+ ##
26
+ # Contains random Ruby utility functions that don't fit anywhere else.
25
27
  module Utility
26
28
  extend self
27
29
 
30
+ ##
31
+ # Generate random alphanumeric passwords.
32
+ #
33
+ # Previously this method generated passwords by shuffling characters
34
+ # in an array. It's now just a wrapper for the +simple-password-gen+
35
+ # gem.
36
+ #
37
+ # @param size [Integer] The length of the password to generate. Defaults
38
+ # to 16 characters if not specified.
39
+ # @param pronounceable [Boolean] True to generate pronounceable passwords.
40
+ # Defaults to false.
41
+ # @return [String] The generated password.
28
42
  def random_alphanumeric(size=16, pronounceable=false)
29
43
  if pronounceable then
30
44
  return Password.pronounceable(size*2)[0..(size-1)]
@@ -1,4 +1,4 @@
1
1
  module TcravitRubyLib
2
- VERSION_DATA = [0, 2, 7]
2
+ VERSION_DATA = [0, 2, 8]
3
3
  VERSION = VERSION_DATA.join(".")
4
4
  end
@@ -28,112 +28,129 @@ require_custom_matcher_named("be_a_rake_task_named")
28
28
  require_custom_matcher_named("be_a_valid_gem_version_file_for")
29
29
  require_custom_matcher_named("declare_the_gem_version_to_be")
30
30
 
31
- TEST_VERSION_FILE = "/tmp/bump_ver.out"
31
+ @test_version_file = "/tmp/bump_ver.out"
32
32
 
33
- describe "version:bump:major", type: :rake do
34
- context "the basics" do
35
- it "should be a rake task" do
36
- expect(subject).to be_a_rake_task_named("version:bump:major")
33
+ describe "bump_ver.rake" do
34
+ describe "version:bump:major", type: :rake do
35
+ before(:all) do
36
+ @test_version_file = "/tmp/bump_ver_major.out"
37
37
  end
38
- end
39
38
 
40
- context "file generation" do
41
- before(:each) do
42
- File.delete(TEST_VERSION_FILE) if File.exist?("/tmp/bump_ver.out")
39
+ context "the basics" do
40
+ it "should be a rake task" do
41
+ expect(subject).to be_a_rake_task_named("version:bump:major")
42
+ end
43
43
  end
44
44
 
45
- it "should generate a file with the right format and module name" do
46
- args = to_task_arguments(1)
47
- task.execute(args)
48
- expect(TEST_VERSION_FILE).to be_a_valid_gem_version_file_for("TcravitRubyLib")
49
- end
45
+ context "file generation" do
46
+ before(:each) do
47
+ File.delete(@test_version_file) if File.exist?(@test_version_file)
48
+ end
50
49
 
51
- it "should increment the major version number" do
52
- initial_version = TcravitRubyLib::VERSION_DATA.clone
53
- args = to_task_arguments(1)
54
- task.execute(args)
55
- expect(TEST_VERSION_FILE).to declare_the_gem_version_to_be((initial_version[0] + 1), initial_version[1], initial_version[2])
56
- end
57
- end
58
- end
50
+ it "should generate a file with the right format and module name" do
51
+ args = to_task_arguments(1)
52
+ task.execute(args)
53
+ expect(@test_version_file).to be_a_valid_gem_version_file_for("TcravitRubyLib")
54
+ end
59
55
 
60
- describe "version:bump:minor", type: :rake do
61
- context "the basics" do
62
- it "should be a rake task" do
63
- expect(subject).to be_a_rake_task_named("version:bump:minor")
56
+ it "should increment the major version number" do
57
+ initial_version = TcravitRubyLib::VERSION_DATA.clone
58
+ args = to_task_arguments(1)
59
+ task.execute(args)
60
+ expect(@test_version_file).to declare_the_gem_version_to_be((initial_version[0] + 1), 0, 0)
61
+ end
64
62
  end
65
63
  end
66
64
 
67
- context "file generation" do
68
- before(:each) do
69
- File.delete(TEST_VERSION_FILE) if File.exist?("/tmp/bump_ver.out")
65
+ describe "version:bump:minor", type: :rake do
66
+ before(:all) do
67
+ @test_version_file = "/tmp/bump_ver_minor.out"
70
68
  end
71
69
 
72
- it "should generate a file with the right format and module name" do
73
- args = to_task_arguments(1)
74
- task.execute(args)
75
- expect(TEST_VERSION_FILE).to be_a_valid_gem_version_file_for("TcravitRubyLib")
70
+ context "the basics" do
71
+ it "should be a rake task" do
72
+ expect(subject).to be_a_rake_task_named("version:bump:minor")
73
+ end
76
74
  end
77
75
 
78
- it "should increment the minor version number" do
79
- initial_version = TcravitRubyLib::VERSION_DATA.clone
80
- args = to_task_arguments(1)
81
- task.execute(args)
82
- expect(TEST_VERSION_FILE).to declare_the_gem_version_to_be(initial_version[0], (initial_version[1] + 1), initial_version[2])
83
- end
84
- end
85
- end
76
+ context "file generation" do
77
+ before(:each) do
78
+ File.delete(@test_version_file) if File.exist?(@test_version_file)
79
+ end
86
80
 
87
- describe "version:bump:build", type: :rake do
88
- context "the basics" do
89
- it "should be a rake task" do
90
- expect(subject).to be_a_rake_task_named("version:bump:build")
81
+ it "should generate a file with the right format and module name" do
82
+ args = to_task_arguments(1)
83
+ task.execute(args)
84
+ expect(@test_version_file).to be_a_valid_gem_version_file_for("TcravitRubyLib")
85
+ end
86
+
87
+ it "should increment the minor version number" do
88
+ initial_version = TcravitRubyLib::VERSION_DATA.clone
89
+ args = to_task_arguments(1)
90
+ task.execute(args)
91
+ expect(@test_version_file).to declare_the_gem_version_to_be(initial_version[0], (initial_version[1] + 1), 0)
92
+ end
91
93
  end
92
94
  end
93
95
 
94
- context "file generation" do
95
- before(:each) do
96
- File.delete(TEST_VERSION_FILE) if File.exist?("/tmp/bump_ver.out")
96
+ describe "version:bump:build", type: :rake do
97
+ before(:all) do
98
+ @test_version_file = "/tmp/bump_ver_build.out"
97
99
  end
98
100
 
99
- it "should generate a file with the right format and module name" do
100
- args = to_task_arguments(1)
101
- task.execute(args)
102
- expect(TEST_VERSION_FILE).to be_a_valid_gem_version_file_for("TcravitRubyLib")
101
+ context "the basics" do
102
+ it "should be a rake task" do
103
+ expect(subject).to be_a_rake_task_named("version:bump:build")
104
+ end
103
105
  end
104
106
 
105
- it "should increment build version number" do
106
- initial_version = TcravitRubyLib::VERSION_DATA.clone
107
- args = to_task_arguments(1)
108
- task.execute(args)
109
- expect(TEST_VERSION_FILE).to declare_the_gem_version_to_be(initial_version[0], initial_version[1], (initial_version[2] + 1))
110
- end
111
- end
112
- end
107
+ context "file generation" do
108
+ before(:each) do
109
+ File.delete(@test_version_file) if File.exist?(@test_version_file)
110
+ end
113
111
 
114
- describe "version:bump:set", type: :rake do
115
- context "the basics" do
116
- it "should be a rake task" do
117
- expect(subject).to be_a_rake_task_named("version:bump:set")
112
+ it "should generate a file with the right format and module name" do
113
+ args = to_task_arguments(1)
114
+ task.execute(args)
115
+ expect(@test_version_file).to be_a_valid_gem_version_file_for("TcravitRubyLib")
116
+ end
117
+
118
+ it "should increment build version number" do
119
+ initial_version = TcravitRubyLib::VERSION_DATA.clone
120
+ args = to_task_arguments(1)
121
+ task.execute(args)
122
+ expect(@test_version_file).to declare_the_gem_version_to_be(initial_version[0], initial_version[1], (initial_version[2] + 1))
123
+ end
118
124
  end
119
125
  end
120
126
 
121
- context "file generation" do
122
- before(:each) do
123
- File.delete(TEST_VERSION_FILE) if File.exist?("/tmp/bump_ver.out")
127
+ describe "version:bump:set", type: :rake do
128
+ before(:all) do
129
+ @test_version_file = "/tmp/bump_ver_set.out"
124
130
  end
125
131
 
126
- it "should generate a file with the right format and module name" do
127
- args = to_task_arguments(3,4,5,11)
128
- task.execute(args)
129
- expect(TEST_VERSION_FILE).to be_a_valid_gem_version_file_for("TcravitRubyLib")
132
+ context "the basics" do
133
+ it "should be a rake task" do
134
+ expect(subject).to be_a_rake_task_named("version:bump:set")
135
+ end
130
136
  end
131
137
 
132
- it "should generate a file with the right version number" do
133
- args = to_task_arguments(3,4,5,1)
134
- task.execute(args)
135
- expect(TEST_VERSION_FILE).to declare_the_gem_version_to_be(3, 4, 5)
138
+ context "file generation" do
139
+ before(:each) do
140
+ File.delete(@test_version_file) if File.exist?(@test_version_file)
141
+ end
142
+
143
+ it "should generate a file with the right format and module name" do
144
+ args = to_task_arguments(3,4,5,11)
145
+ task.execute(args)
146
+ expect(@test_version_file).to be_a_valid_gem_version_file_for("TcravitRubyLib")
147
+ end
148
+
149
+ it "should generate a file with the right version number" do
150
+ args = to_task_arguments(3,4,5,1)
151
+ task.execute(args)
152
+ expect(@test_version_file).to declare_the_gem_version_to_be(3, 4, 5)
153
+ end
136
154
  end
137
155
  end
138
156
  end
139
-
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tcravit_ruby_lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tammy Cravit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-05 00:00:00.000000000 Z
11
+ date: 2018-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simple-password-gen