job_spec 0.1.0 → 0.2.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: 3441a2fabbdaac81b867f6b54a9839be629f280a
4
- data.tar.gz: 952a87d62a7c4771e32b1b55a4ebcdede38de96c
3
+ metadata.gz: 6f22f45a0f55d70cc8e2654637dd04c308373118
4
+ data.tar.gz: c9f013e894133a601a24ec387aa7e2c5fb4ea0ef
5
5
  SHA512:
6
- metadata.gz: 1048289aa27457a9908c9356707bcb2563dd067c037b3e26c0005b35d455e8f8ae762dfd82caf02a0faec7612cb59bb82fc9c161ca8b88719d9c3120baf4494b
7
- data.tar.gz: 4fb1bf8b6cff0db7fb5658125dcd8919c7fcc08160f09492930cb1eab6c4abc66db26002cc1f3bad112fffd15c8deb86a3ba0e3fba4f500100c9458568b6e478
6
+ metadata.gz: df1d6ddf2fa1dfff30e7bc6d0ce272a48e4bca7f445b0b88e86fec78d4bb5809201a82ba6635c715234cfd68af04c16f5131387e724e4280e8da69daffcd7b84
7
+ data.tar.gz: b339882289260efc2e022c32a1c6673be2f29d0f21a1e55902bd4dacf521857ca6d47ed4ea34560b60b40f51784a7a3241597db5505db4764fb9df83125c4c0c
data/README.md CHANGED
@@ -23,7 +23,7 @@ end
23
23
  Save that into a file `roles/engineer.rb`. Now from the command line in the directory that contains the `roles/` directory:
24
24
 
25
25
  ```
26
- jobspec build roles
26
+ jobspec build --in=roles --out=dist
27
27
  ```
28
28
 
29
29
  And you will see your job roles printed out.
data/lib/job_spec/cli.rb CHANGED
@@ -3,12 +3,21 @@ require 'job_spec'
3
3
 
4
4
  module JobSpec
5
5
  class CLI < Thor
6
- desc 'build DIR', 'build roles in DIR'
7
- def build(path = '.')
8
- print "Building roles in #{path}... "
9
- Dir[File.join(Dir.pwd, path, '**/*.rb')].each { |f| require f }
10
- puts 'done.'
11
- p Role.definitions
6
+ desc 'build', 'build roles in DIR out to DIR'
7
+ option :in, required: true
8
+ option :out, required: true
9
+ def build
10
+ puts "Looking in '#{options[:in]}' for roles... "
11
+ role_files(options[:in]).each do |f|
12
+ require f
13
+ end
14
+
15
+ FileUtils.mkdir_p(path_relative_to_pwd(options[:out]))
16
+ Role.definitions.each do |role|
17
+ puts "Saving #{role.name} to #{safe_role_out_path(role)}..."
18
+ File.write(safe_role_out_path(role), RenderAsMarkdown.new(role).render)
19
+ end
20
+ puts 'Finished.'
12
21
  end
13
22
 
14
23
  map %w(--version -v) => :version
@@ -19,3 +28,23 @@ module JobSpec
19
28
  end
20
29
  end
21
30
  end
31
+
32
+ def path_relative_to_pwd(path)
33
+ File.expand_path(path, Dir.pwd)
34
+ end
35
+
36
+ def path_glob(dir)
37
+ path_relative_to_pwd(File.join(dir, '**/*.rb'))
38
+ end
39
+
40
+ def role_files(dir)
41
+ Dir[path_glob(dir)]
42
+ end
43
+
44
+ def safe_role_name(role)
45
+ "#{role.name.downcase.gsub(/[^a-z]+/, '')}.md"
46
+ end
47
+
48
+ def safe_role_out_path(role)
49
+ File.join(path_relative_to_pwd(options[:out]), safe_role_name(role))
50
+ end
@@ -0,0 +1,22 @@
1
+ module JobSpec
2
+ class RenderAsMarkdown
3
+ attr_reader :role
4
+
5
+ def initialize(role)
6
+ @role = role
7
+ end
8
+
9
+ def render
10
+ markdown = []
11
+ markdown << "# #{role.name}"
12
+ markdown << role.description unless role.description.nil?
13
+
14
+ role.expectations.map(&:values).each do |(expectation, description)|
15
+ markdown << "## #{expectation.capitalize}"
16
+ markdown << description.capitalize unless description.nil?
17
+ end
18
+
19
+ markdown.join("\n\n")
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,53 @@
1
+ module JobSpec
2
+ class Role
3
+ def self.definition(name, &block)
4
+ @definitions ||= []
5
+ @definitions << new(name, &block)
6
+ end
7
+
8
+ def self.definitions
9
+ @definitions
10
+ end
11
+
12
+ def initialize(name, &block)
13
+ @name = name
14
+ @expectations = []
15
+ instance_eval(&block) if block_given?
16
+ end
17
+
18
+ def name
19
+ @name
20
+ end
21
+
22
+ def description(description = nil)
23
+ @description = @description || description
24
+ end
25
+
26
+ def salary(range = nil)
27
+ @salary = @salary || range
28
+ end
29
+
30
+ def include(role_expectations)
31
+ @expectations.concat(role_expectations.to_a)
32
+ end
33
+
34
+ def expected(expectation, description = nil)
35
+ @expectations << { expectation: expectation, description: description }
36
+ end
37
+
38
+ def expectations
39
+ @expectations
40
+ end
41
+
42
+ class Expectations
43
+ def self.expected(expectation)
44
+ @role ||= Role.new(self.class.name)
45
+ @role.expected(expectation)
46
+ end
47
+
48
+ def self.to_a
49
+ @role.expectations
50
+ end
51
+ end
52
+ end
53
+ end
@@ -1,3 +1,3 @@
1
1
  module JobSpec
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
data/lib/job_spec.rb CHANGED
@@ -1,45 +1,2 @@
1
- module JobSpec
2
- class Role
3
- def self.definition(name, &block)
4
- @definitions ||= []
5
- @definitions << new(name, &block)
6
- end
7
-
8
- def self.definitions
9
- @definitions
10
- end
11
-
12
- def initialize(name, &block)
13
- @name = name
14
- @expectations = []
15
- instance_eval(&block) if block_given?
16
- end
17
-
18
- def salary(range = nil)
19
- @salary = @salary || range
20
- end
21
-
22
- def include(role_expectations)
23
- @expectations.concat(role_expectations.to_a)
24
- end
25
-
26
- def expected(expectation)
27
- @expectations << expectation
28
- end
29
-
30
- def to_a
31
- @expectations
32
- end
33
-
34
- class Expectations
35
- def self.expected(expectation)
36
- @role ||= Role.new(self.class.name)
37
- @role.expected(expectation)
38
- end
39
-
40
- def self.to_a
41
- @role.to_a
42
- end
43
- end
44
- end
45
- end
1
+ require 'job_spec/role'
2
+ require 'job_spec/render_as_markdown'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: job_spec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luke Morton
@@ -83,6 +83,8 @@ files:
83
83
  - job_spec.gemspec
84
84
  - lib/job_spec.rb
85
85
  - lib/job_spec/cli.rb
86
+ - lib/job_spec/render_as_markdown.rb
87
+ - lib/job_spec/role.rb
86
88
  - lib/job_spec/version.rb
87
89
  homepage: https://github.com/madetech/job_spec
88
90
  licenses: