relationships 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d0857e3692b19aa05daecc73688b8187611f1b0f
4
+ data.tar.gz: 7cb2372bf794b09d8d5d2d10499c12cef026e320
5
+ SHA512:
6
+ metadata.gz: 0aee99da0fc41dbe96605b2447566f8b82e586921d40d104088d750ee7164aeda4d7928b78b0408284acbb83df22112cbc43c340b0a0e4f093662a0edf023d0a
7
+ data.tar.gz: adff1cadfae2a6ff4a7be20f7c0e262dfeba280cb9b8d8d32474910b3a48e82aab2eec9de4eaaa12e2726bdfc5d39cd133506128280ac1bb6489d4aa33dc8ebb
data/bin/relationships ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'relationships'
4
+
5
+ relationships.run!
@@ -0,0 +1,11 @@
1
+ require 'rails'
2
+
3
+ Dir['./lib/relationships/*'].map {|m| require m}
4
+
5
+ class Relationships
6
+ def self.run!
7
+ model_files = Dir[Pathname.new('app/models/*')]
8
+ models = FileParser.parse model_files
9
+ MarkdownGenerator.output models
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ class FileParser
2
+ def self.parse model_files
3
+ models = model_files.map do |model_file|
4
+ Model.from_file model_file
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,34 @@
1
+ class MarkdownGenerator
2
+ attr_accessor :models, :relationships_path
3
+
4
+ def self.output(models)
5
+ generator = MarkdownGenerator.new models: models
6
+ generator.output!
7
+ end
8
+
9
+ def initialize(args = {})
10
+ @relationships_path = Pathname.new('').join 'relationships'
11
+ @models = args[:models]
12
+ make_relationships_directory
13
+ end
14
+
15
+ def file
16
+ @output_file ||= File.new(relationships_path.join('relationships.md'), 'w')
17
+ end
18
+
19
+ def output!
20
+ models.each do |model|
21
+ file.write "\n# #{model.class_name}\n"
22
+ model.relationships.each do |relationshipship|
23
+ file.write "* #{relationshipship}\n"
24
+ end
25
+ end
26
+ file.close
27
+ end
28
+
29
+ private
30
+
31
+ def make_relationships_directory
32
+ Dir.mkdir @relationships_path unless Dir.exists? @relationships_path
33
+ end
34
+ end
@@ -0,0 +1,30 @@
1
+ class Model
2
+ attr_accessor :file_contents, :file_path
3
+
4
+ def self.from_file(file)
5
+ Model.new file: file
6
+ end
7
+
8
+ def initialize(args = {})
9
+ @file_path = args[:file]
10
+ @file_contents = File.read file_path if file_path
11
+ end
12
+
13
+ def relationships
14
+ @relationships ||= extract_relationships
15
+ end
16
+
17
+ def file_name
18
+ file_path[/\w+\.rb/]
19
+ end
20
+
21
+ def class_name
22
+ file_name[/\w+/].camelize
23
+ end
24
+
25
+ private
26
+
27
+ def extract_relationships
28
+ @file_contents.scan /belongs_to.+$|has_many.+$|has_one.+$|has_and_belongs_to_many.+$/
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: relationships
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Kofink
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-03 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: One simply calls rake relationships to generate relation output.
14
+ email: ajkofink@gmail.com
15
+ executables:
16
+ - relationships
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/relationships.rb
21
+ - lib/relationships/file_parser.rb
22
+ - lib/relationships/markdown_generator.rb
23
+ - lib/relationships/model.rb
24
+ - bin/relationships
25
+ homepage: https://github.com/akofink/relationships
26
+ licenses:
27
+ - Beerware
28
+ metadata: {}
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 2.0.3
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: Compiles a list of ActiveRecord relationships in a Rails application.
49
+ test_files: []