codeinventory 0.1.2 → 0.1.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0466434f7ce5176346394af5842accdb4bc649cd
4
- data.tar.gz: b3f98cf215d6b6f5739d137cb5db87df0e45b8a7
3
+ metadata.gz: bb626c63a1233fa953e0a8ab80b66fb4cb958537
4
+ data.tar.gz: ffe05f5c9eee82879827b2a452bea822a7545c83
5
5
  SHA512:
6
- metadata.gz: 47467123b0e59a32e04f744f34e5e951d506920c8c1cb6c64e7c78d70998891094e4260d3d4c0f51a244dbf1e08427cef20aa0413672d24de1ed8bb8864f3731
7
- data.tar.gz: aec125c4b76b049d8b81fac3663914f4509de0e3178dee1863b8b955a78ebd861dedd74e5c8048cb83addf65c71bfa2257373fe367856ff7584745cba3f5626a
6
+ metadata.gz: 092d0c1d9cd87baf6369944bde702a1b66d48393ec506eabd84508c6c858f2ad41520518800cff2236046f7c910d3a8af9abe7292de719a090b89993b787d8c6
7
+ data.tar.gz: 3516d81dbc3645f2b5e77490b79f768873c2a47e50a6076d58ae6f3f0b7db3feb324645e12e1838fcce96d8265554ff4c74d3123072148771d16670b058d8c70
data/README.md CHANGED
@@ -2,15 +2,30 @@
2
2
 
3
3
  *_This is an experimental gem that is currently in an alpha stage. The features and interface are unstable and may change at any time._*
4
4
 
5
- The `codeinventory` gem is a tool to harvest project metadata from an agency's repositories. The harvested metadata can be used to produce a [code.json](https://code.gov/#/policy-guide/docs/compliance/inventory-code) file for [Code.gov](https://code.gov/). The gem includes the ability to pull project metadata from these sources:
5
+ The `codeinventory` gem is provides a CLI tool and a programmatic interface to harvest project metadata from an agency's repositories. The harvested metadata can be used to produce a [code.json](https://code.gov/#/policy-guide/docs/compliance/inventory-code) file for [Code.gov](https://code.gov/). The gem includes the ability to pull project metadata from these sources:
6
6
 
7
7
  * JSON files
8
8
  * CSV files
9
9
 
10
- More sources can be added via plugins.
10
+ More sources can be added via plugins:
11
+
12
+ * [GitHub](https://github.com/GSA/codeinventory-github)
13
+
14
+ ## Table of Contents
15
+
16
+ * [Installation](#installation)
17
+ * [Usage](#usage)
18
+ * [CLI](#cli)
19
+ * [JSON Source](#json-source)
20
+ * [CSV Source](#csv-source)
21
+ * [Multiple Sources](#multiple-sources)
22
+ * [Development](#development)
23
+ * [Contributing](#contributing)
11
24
 
12
25
  ## Installation
13
26
 
27
+ You will need [Ruby](https://www.ruby-lang.org/en/) on your system in order to install and use this gem.
28
+
14
29
  Add this line to your application's Gemfile:
15
30
 
16
31
  ```ruby
@@ -27,18 +42,47 @@ Or install it yourself as:
27
42
 
28
43
  ## Usage
29
44
 
30
- Basically:
45
+ ### CLI
31
46
 
32
- ```ruby
33
- json_source = CodeInventory::JSONFile.new(File.new("some_projects.json"))
34
- csv_source = CodeInventory::CSVFile.new(File.new("more_projects.csv"))
47
+ After installing this gem, you can run `codeinv`, an extensible command-line interface (CLI).
35
48
 
36
- inventory = CodeInventory::Inventory.new(json_source, csv_source)
37
- inventory.projects # Returns an array of all projects in the JSON and CSV files
38
49
  ```
50
+ $ codeinv
51
+ Commands:
52
+ codeinv csv FILENAME # Build an inventory from a CSV file
53
+ codeinv help [COMMAND] # Describe available commands or one specific command
54
+ codeinv json FILENAME # Build an inventory from a JSON file
55
+ ```
56
+
57
+ To generate a code inventory from an existing CSV file, for instance:
58
+
59
+ ```
60
+ codeinv csv my_csv_file.csv
61
+ ```
62
+
63
+ For information on the required format of JSON and CSV input files, see [JSON Source](#json-source) and [CSV Source](#csv-source).
64
+
65
+ The CLI can be extended to support other sources just by installing a gem. For instance, if you install the [codeinventory-github](https://github.com/GSA/codeinventory-github) gem, you'll automatically get the `github` subcommand:
66
+
67
+ ```
68
+ $ codeinv
69
+ Commands:
70
+ codeinv csv FILENAME # Build an inventory from a CSV file
71
+ codeinv github GITHUB_ACCESS_TOKEN GITHUB_ORG [OPTIONS] # Build an inventory from GitHub
72
+ codeinv help [COMMAND] # Describe available commands or one s...
73
+ codeinv json FILENAME # Build an inventory from a JSON file
74
+ ```
75
+
39
76
 
40
77
  ### JSON Source
41
78
 
79
+ ```ruby
80
+ json_source = CodeInventory::JSONFile.new(File.new("some_projects.json"))
81
+
82
+ inventory = CodeInventory::Inventory.new(json_source)
83
+ inventory.projects # Returns an array of all projects in the JSON file
84
+ ```
85
+
42
86
  When using `CodeInventory::JSONFile`, the source file is expected to be a JSON file in the following format:
43
87
 
44
88
  ```json
@@ -78,6 +122,13 @@ See the [Code.gov documentation](https://code.gov/#/policy-guide/docs/compliance
78
122
 
79
123
  ### CSV Source
80
124
 
125
+ ```ruby
126
+ csv_source = CodeInventory::CSVFile.new(File.new("more_projects.csv"))
127
+
128
+ inventory = CodeInventory::Inventory.new(csv_source)
129
+ inventory.projects # Returns an array of all projects in the CSV file
130
+ ```
131
+
81
132
  When using `CodeInventory::CSVFile`, the source file is expected to be a CSV file in the following format:
82
133
 
83
134
  ```csv
@@ -88,6 +139,18 @@ Product Two,Another awesome product.,http://www.usa.gov/publicdomain/label/1.0/,
88
139
 
89
140
  See the [Code.gov documentation](https://code.gov/#/policy-guide/docs/compliance/inventory-code) for specifics on required fields and value types.
90
141
 
142
+ ### Multiple Sources
143
+
144
+ You can combine multiple sources when building an inventory.
145
+
146
+ ```ruby
147
+ json_source = CodeInventory::JSONFile.new(File.new("some_projects.json"))
148
+ csv_source = CodeInventory::CSVFile.new(File.new("more_projects.csv"))
149
+
150
+ inventory = CodeInventory::Inventory.new(json_source, csv_source)
151
+ inventory.projects # Returns an array of all projects in the JSON and CSV files
152
+ ```
153
+
91
154
  ## Development
92
155
 
93
156
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -12,7 +12,7 @@ module CodeInventory
12
12
  def projects
13
13
  @csv.collect do |row|
14
14
  csv_data = row.to_hash
15
- csv_data.inject({}) do |memo, pair|
15
+ project = csv_data.inject({}) do |memo, pair|
16
16
  csv_header, csv_value = pair
17
17
  case
18
18
  when csv_header == "tags"
@@ -24,6 +24,8 @@ module CodeInventory
24
24
  end
25
25
  memo.merge(new_pair)
26
26
  end
27
+ yield project if block_given?
28
+ project
27
29
  end
28
30
  end
29
31
 
@@ -7,7 +7,12 @@ module CodeInventory
7
7
  end
8
8
 
9
9
  def projects
10
- @sources.collect { |source| source.projects }.flatten
10
+ @sources.collect { |src|
11
+ src.projects do |project|
12
+ yield project, src if block_given?
13
+ project
14
+ end
15
+ }.flatten
11
16
  end
12
17
  end
13
18
  end
@@ -2,10 +2,15 @@ require "json"
2
2
 
3
3
  module CodeInventory
4
4
  class JSONFile
5
- attr_accessor :projects
6
-
7
5
  def initialize(json_file)
8
6
  @projects = JSON.load(json_file)
9
7
  end
8
+
9
+ def projects
10
+ if block_given?
11
+ @projects.each { |p| yield p }
12
+ end
13
+ @projects
14
+ end
10
15
  end
11
16
  end
@@ -1,3 +1,3 @@
1
1
  module CodeInventory
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codeinventory
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Fredrickson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-09 00:00:00.000000000 Z
11
+ date: 2017-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler