docketeer 0.1.0
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.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/bin/docket +52 -0
- data/config/config.rb +74 -0
- data/config/config.yml +2 -0
- data/docketeer.gemspec +22 -0
- data/lib/docketeer.rb +8 -0
- data/lib/docketeer/logger.rb +45 -0
- data/lib/docketeer/project.rb +32 -0
- data/lib/docketeer/version.rb +3 -0
- metadata +69 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/bin/docket
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../lib/docketeer'
|
4
|
+
|
5
|
+
|
6
|
+
# :name is optional, otherwise uses the basename of this executable
|
7
|
+
program :name, 'Docketeer'
|
8
|
+
program :version, Docketeer::VERSION
|
9
|
+
program :description, 'Manage your projects'
|
10
|
+
|
11
|
+
|
12
|
+
command :new do |c|
|
13
|
+
# Describe this command
|
14
|
+
c.syntax = 'docket new [options] <client name> <project name>'
|
15
|
+
c.description = 'Creates a new project docket'
|
16
|
+
|
17
|
+
# accept --path as an option
|
18
|
+
c.option '--path STRING', String, 'Use this root folder to store this project'
|
19
|
+
|
20
|
+
c.action do |args, options|
|
21
|
+
# Use arguments or ask if not found
|
22
|
+
client = args[0] || ask("Enter client name: ")
|
23
|
+
project = args[1] || ask("Enter project name: ")
|
24
|
+
|
25
|
+
# Create a new project
|
26
|
+
puts options.path
|
27
|
+
Docketeer::Project.new(client, project, options)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
command :config do |c|
|
33
|
+
# Describe this command
|
34
|
+
c.syntax = 'docket config [options]'
|
35
|
+
c.description = 'shows or modifies configuration variables'
|
36
|
+
|
37
|
+
c.option '--project_dir FILE', 'Set the default root folder for your projects'
|
38
|
+
c.option '--log_path FILE', "Set the path to the log file (a new one will be created if it doesn't already exist"
|
39
|
+
|
40
|
+
c.action do |args, options|
|
41
|
+
config = Docketeer::Config.new
|
42
|
+
|
43
|
+
# Set the defaults from the current config file
|
44
|
+
options.default(
|
45
|
+
:project_dir => File.expand_path(config.project_dir),
|
46
|
+
:log_path => File.expand_path(config.log_path)
|
47
|
+
)
|
48
|
+
|
49
|
+
config.set_project_dir(options.project_dir)
|
50
|
+
config.set_log_path(options.log_path)
|
51
|
+
end
|
52
|
+
end
|
data/config/config.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
module Docketeer
|
2
|
+
class Config
|
3
|
+
attr_accessor :project_dir
|
4
|
+
attr_accessor :log_path
|
5
|
+
attr_accessor :config_path
|
6
|
+
|
7
|
+
PROJECT_DIR = File.expand_path("~/Projects/")
|
8
|
+
LOG_PATH = File.expand_path("~/Projects/.projects.log")
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@config_path = File.join(File.dirname(__FILE__), 'config.yml')
|
12
|
+
unless File.exists?(@config_path) && YAML.load_file(@config_path)
|
13
|
+
File.open(@config_path, 'a+') do |file|
|
14
|
+
file.puts "project_dir: #{ PROJECT_DIR }"
|
15
|
+
file.puts "log_path: #{ LOG_PATH }"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
config = YAML.load_file(@config_path)
|
19
|
+
@log_path = File.expand_path(config['log_path']) || PROJECT_DIR
|
20
|
+
@project_dir = File.expand_path(config['project_dir']) || LOG_PATH
|
21
|
+
end
|
22
|
+
|
23
|
+
def show
|
24
|
+
config = YAML.load_file(self.config_path)
|
25
|
+
config.each do |key, value|
|
26
|
+
puts [key, value].join(": ")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def set_project_dir(path)
|
31
|
+
if File.file?(path)
|
32
|
+
puts "Error: #{ path } is the name of an existing file. Please name a new or existing directory to use as your default project folder."
|
33
|
+
return false
|
34
|
+
else
|
35
|
+
puts "project_dir: #{ File.expand_path path }"
|
36
|
+
update_config_file('project_dir', path)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def set_log_path(path)
|
41
|
+
if File.directory?(path)
|
42
|
+
puts "Error: #{ path } is a directory. Please name a new or existing file to use as the log file."
|
43
|
+
return false
|
44
|
+
else
|
45
|
+
puts "log_path: #{ File.expand_path path }"
|
46
|
+
update_config_file('log_path', path)
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def update_config_file(key_to_update, value)
|
55
|
+
config = YAML.load_file(self.config_path)
|
56
|
+
new_value = File.expand_path(value)
|
57
|
+
old_value = File.expand_path(config[key_to_update])
|
58
|
+
if new_value == old_value
|
59
|
+
return false
|
60
|
+
else
|
61
|
+
config[key_to_update] = new_value
|
62
|
+
|
63
|
+
File.open(self.config_path, 'w') do |file|
|
64
|
+
config.each do |key, value|
|
65
|
+
file.puts([key, value].join(': '))
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
return true
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
data/config/config.yml
ADDED
data/docketeer.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "docketeer/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "docketeer"
|
7
|
+
s.version = Docketeer::VERSION
|
8
|
+
s.authors = ["Christian Naths"]
|
9
|
+
s.email = ["christiannaths@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Create and organize projects using by client name using unique docket numbers.}
|
12
|
+
s.description = %q{This gem will create a new folder structure for new projects and place them in a folder named with the name of the client. }
|
13
|
+
|
14
|
+
s.rubyforge_project = "docketeer"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_dependency("commander", '>= 4.0.4')
|
22
|
+
end
|
data/lib/docketeer.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'commander/import'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'yaml'
|
5
|
+
require File.join(File.dirname(__FILE__), 'docketeer', 'version')
|
6
|
+
require File.join(File.dirname(__FILE__), '/../config', 'config')
|
7
|
+
require File.join(File.dirname(__FILE__), 'docketeer', 'logger')
|
8
|
+
require File.join(File.dirname(__FILE__), 'docketeer', 'project')
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Docketeer
|
2
|
+
class Logger
|
3
|
+
attr_accessor :path
|
4
|
+
|
5
|
+
# Create a new log file if one doesn't already exist.
|
6
|
+
# returns the log file to the class
|
7
|
+
def initialize(path)
|
8
|
+
@path = File.expand_path(path)
|
9
|
+
log = File.new(@path, 'a+')
|
10
|
+
end
|
11
|
+
|
12
|
+
# Add an entry to the log file
|
13
|
+
# and return the message back to
|
14
|
+
# the class
|
15
|
+
def add(message)
|
16
|
+
File.open(self.path, "a+") do |file|
|
17
|
+
file.puts(message)
|
18
|
+
end
|
19
|
+
return message
|
20
|
+
end
|
21
|
+
|
22
|
+
# Read the last line of the log file
|
23
|
+
def last
|
24
|
+
File.open(self.path, 'a+') do |file|
|
25
|
+
line = file.readlines.last
|
26
|
+
{
|
27
|
+
:id => line[0..4],
|
28
|
+
:year_prefix => line[0..1],
|
29
|
+
:docket_id => line[2..4]
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Generate the next docket number
|
35
|
+
def next
|
36
|
+
current_year_prefix = Time.now.strftime("%y")
|
37
|
+
number = "#{ current_year_prefix }001"
|
38
|
+
if self.last[:year_prefix] == current_year_prefix
|
39
|
+
number = (self.last[:id].to_i + 1).to_s
|
40
|
+
end
|
41
|
+
return number
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Docketeer
|
2
|
+
class Project
|
3
|
+
|
4
|
+
# Create a new project
|
5
|
+
def initialize(client, project, options)
|
6
|
+
# Instantiate config object
|
7
|
+
config = Docketeer::Config.new
|
8
|
+
|
9
|
+
# Set Default options if none were given
|
10
|
+
options.default(:path => config.project_dir)
|
11
|
+
|
12
|
+
# Instantiate logger object
|
13
|
+
logger = Docketeer::Logger.new(config.log_path)
|
14
|
+
|
15
|
+
# Generate a new, unique docket number
|
16
|
+
# using the Logger class
|
17
|
+
docket = logger.next
|
18
|
+
|
19
|
+
# Set the project path and create the folders
|
20
|
+
project_path = File.join(File.expand_path(options.path), client, "#{ docket } #{ project }")
|
21
|
+
FileUtils.mkdir_p(project_path)
|
22
|
+
|
23
|
+
# Add a log entry using the Logger class
|
24
|
+
logger.add([docket, client, project, project_path, Time.now.to_s].join(", "))
|
25
|
+
|
26
|
+
puts "Initializing #{ project_path }"
|
27
|
+
puts "Logging to #{ logger.path }"
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: docketeer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Christian Naths
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-08-07 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: commander
|
16
|
+
requirement: &70123823825120 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 4.0.4
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70123823825120
|
25
|
+
description: ! 'This gem will create a new folder structure for new projects and place
|
26
|
+
them in a folder named with the name of the client. '
|
27
|
+
email:
|
28
|
+
- christiannaths@gmail.com
|
29
|
+
executables:
|
30
|
+
- docket
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- .gitignore
|
35
|
+
- Gemfile
|
36
|
+
- Rakefile
|
37
|
+
- bin/docket
|
38
|
+
- config/config.rb
|
39
|
+
- config/config.yml
|
40
|
+
- docketeer.gemspec
|
41
|
+
- lib/docketeer.rb
|
42
|
+
- lib/docketeer/logger.rb
|
43
|
+
- lib/docketeer/project.rb
|
44
|
+
- lib/docketeer/version.rb
|
45
|
+
homepage: ''
|
46
|
+
licenses: []
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubyforge_project: docketeer
|
65
|
+
rubygems_version: 1.8.6
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: Create and organize projects using by client name using unique docket numbers.
|
69
|
+
test_files: []
|