technologist 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: 64dec81accfcda79b977750e32b8bc61a96f7b61
4
- data.tar.gz: b5fbc327799092308ac3765bef95c98bacc0bc56
3
+ metadata.gz: 0702a8fcc2a5cb321b18b1eeecd77fa506acaade
4
+ data.tar.gz: ee9bae10218646991f9c6368c863a1465b0a79ed
5
5
  SHA512:
6
- metadata.gz: de3da25bc97325009cffc248612bc4498aab9ee8f15a235503962cd6147d7fa71d90835b9c329934af80a02d37b15a1c0c8ff80d169139ae25cab5fab14903a6
7
- data.tar.gz: 5a6fa0cfa096ef7261590efecadfa7dd15a19e94cdfe46ea53c1777ef0b244ad717594926c9c814e23b9b96e19e0726f28e5ebc5f96553440f4e82dbe2b8f017
6
+ metadata.gz: 4bdf9f824a3a4437f7402ad55e1d99713d5bec201eaa8f8a67cace1b6b8457d450856f4ec046ec619ada9f5b5beed05fce252ba32d0323c02f29c6c00096d690
7
+ data.tar.gz: 971c2070f033c4483813779f786f5c114c60aa437570bc10ed402008df353700db69049934bc88a903979a8e04a14eeacbfcf132a5ba83e3e99a61b564cea012
data/.travis.yml CHANGED
@@ -1,3 +1,4 @@
1
1
  language: ruby
2
+ cache: bundler
2
3
  rvm:
3
4
  - 2.0.0
data/lib/technologist.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'technologist/version'
2
2
  require 'technologist/repository'
3
+ Dir[File.expand_path('../technologist/rules/*.rb', __FILE__)].each { |file| require file }
3
4
 
4
5
  module Technologist
5
6
  end
@@ -34,13 +34,7 @@ module Technologist
34
34
  begin
35
35
  rules.map do |technology, definition|
36
36
  definition['rules'].map do |rule|
37
- rule = rule.flatten
38
- file_name = rule.first
39
- pattern = rule.last
40
- # may use single or double quotes
41
- pattern = pattern.gsub(/["']/, %q{["']})
42
-
43
- if repository.file_content(file_name) =~ /#{pattern}/
37
+ if rule.matches?(technology, repository)
44
38
  technology
45
39
  end
46
40
  end
@@ -1,26 +1,39 @@
1
- Locomotive:
1
+ Rails:
2
2
  rules:
3
- - Gemfile: ^\s*gem 'locomotivecms_wagon'
4
- primary: Rails
3
+ - !ruby/object:GemRule {}
5
4
 
6
- Rails:
5
+ Locomotive:
7
6
  rules:
8
- - Gemfile: ^\s*gem 'rails'
7
+ - !ruby/object:GemRule { gem_name: 'locomotivecms_wagon' }
8
+ primary: Rails
9
9
 
10
10
  Magnolia:
11
11
  rules:
12
- - pom.xml: <magnoliaVersion>
12
+ - !ruby/object:FileContentRule { file_name: 'pom.xml', file_content_pattern: '<magnoliaVersion>' }
13
13
 
14
14
  Sinatra:
15
15
  rules:
16
- - config.ru: run Sinatra::Application
17
- - Gemfile: ^\s*gem 'sinatra'
16
+ - !ruby/object:FileContentRule { file_name: 'config.ru', file_content_pattern: 'run Sinatra::Application' }
17
+ - !ruby/object:GemRule {}
18
18
 
19
19
  Dashing:
20
20
  rules:
21
- - Gemfile: ^\s*gem 'dashing'
21
+ - !ruby/object:GemRule {}
22
22
  primary: Sinatra
23
23
 
24
24
  Middleman:
25
25
  rules:
26
- - Gemfile: ^\s*gem 'middleman'
26
+ - !ruby/object:GemRule {}
27
+
28
+ Meteor:
29
+ rules:
30
+ - !ruby/object:DirectoryPresenceRule { directory_name: '.meteor' }
31
+
32
+ Spree:
33
+ rules:
34
+ - !ruby/object:GemRule { gem_name: 'spree' }
35
+ primary: Rails
36
+
37
+ Wordpress:
38
+ rules:
39
+ - !ruby/object:FilePresenceRule { file_name: 'wp-settings.php' }
@@ -18,30 +18,51 @@ module Technologist
18
18
  #
19
19
  # @return [String] The content of the file or nil if the file cannot be found.
20
20
  def file_content(file_name)
21
- file = find_file(file_name)
21
+ file = find_blob(file_name)
22
22
 
23
23
  file.content if file
24
24
  end
25
25
 
26
- # Recursively searches for the file identified by `file_name`
27
- # in all subdirectories in the repository.
26
+ # Recursively searches for the blob identified by `blob_name`
27
+ # in all subdirectories in the repository. A blob is usually either
28
+ # a file or a directory.
28
29
  #
29
- # @param file_name [String] the file name
30
- # @param current_tree [Rugged::Tree] the git directory tree in which to look for the file.
30
+ # @param blob_name [String] the blob name
31
+ # @param current_tree [Rugged::Tree] the git directory tree in which to look for the blob.
31
32
  # Defaults to the root tree (see `#root_tree`).
32
33
  #
33
- # @return [Rugged::Blob] The file blob or nil if it cannot be found.
34
- def find_file(file_name, current_tree = root_tree)
35
- file = current_tree[file_name]
34
+ # @return [Rugged::Blob] The blob blob or nil if it cannot be found.
35
+ def find_blob(blob_name, current_tree = root_tree)
36
+ blob = current_tree[blob_name]
36
37
 
37
- if file
38
- repository.lookup(file[:oid])
38
+ if blob
39
+ repository.lookup(blob[:oid])
39
40
  else
40
41
  current_tree.each_tree do |sub_tree|
41
- file = find_file(file_name, repository.lookup(sub_tree[:oid]))
42
- break file if file
42
+ blob = find_blob(blob_name, repository.lookup(sub_tree[:oid]))
43
+ break blob if blob
43
44
  end
44
45
  end
45
46
  end
47
+
48
+ # Looks for a directory and returns true when the directory
49
+ # can be found.
50
+ #
51
+ # @param directory_name [String] the directory name
52
+ #
53
+ # @return [Boolean] true if the directory can be found.
54
+ def directory_exists?(directory_name)
55
+ !!find_blob(directory_name)
56
+ end
57
+
58
+ # Looks for a file and returns true when the file
59
+ # can be found.
60
+ #
61
+ # @param file_name [String] the file name
62
+ #
63
+ # @return [Boolean] true if the file can be found.
64
+ def file_exists?(file_name)
65
+ !!find_blob(file_name)
66
+ end
46
67
  end
47
68
  end
@@ -0,0 +1,9 @@
1
+ require 'technologist/rules/rule'
2
+
3
+ class DirectoryPresenceRule < Rule
4
+ attr_accessor :directory_name
5
+
6
+ def matches?(framework_name, repository)
7
+ repository.directory_exists?(directory_name)
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require 'technologist/rules/rule'
2
+
3
+ class FileContentRule < Rule
4
+ attr_accessor :file_name, :file_content_pattern
5
+
6
+ def matches?(framework_name, repository)
7
+ !!(repository.file_content(file_name) =~ /#{file_content_pattern}/)
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require 'technologist/rules/rule'
2
+
3
+ class FilePresenceRule < Rule
4
+ attr_accessor :file_name
5
+
6
+ def matches?(framework_name, repository)
7
+ repository.file_exists?(file_name)
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ require 'technologist/rules/file_content_rule'
2
+
3
+ class GemRule < FileContentRule
4
+ attr_accessor :gem_name
5
+
6
+ def matches?(framework_name, repository)
7
+ self.file_name = 'Gemfile'
8
+ self.gem_name ||= framework_name.downcase
9
+ self.file_content_pattern = /^\s*gem ["']#{gem_name}["']/
10
+
11
+ super
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ class Rule
2
+ def initialize(attributes = {})
3
+ attributes.each { |name, value| self.send(:"#{name}=", value) }
4
+ end
5
+
6
+ def matches?(framework_name, repository)
7
+ false
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module Technologist
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/technologist.gemspec CHANGED
@@ -10,8 +10,9 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["mail@koffeinfrei.org"]
11
11
 
12
12
  spec.summary = %q{Detects the technologies used in a repository.}
13
- spec.description = %q{}
13
+ spec.description = %q{Detects technologies in a repository by applying a set of rules and returning primary and secondary frameworks.}
14
14
  spec.homepage = "https://github.com/github/koffeinfrei/linguist"
15
+ spec.license = "AGPL-3.0"
15
16
 
16
17
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
18
  spec.bindir = "exe"
@@ -22,5 +23,5 @@ Gem::Specification.new do |spec|
22
23
 
23
24
  spec.add_development_dependency "bundler", "~> 1.7"
24
25
  spec.add_development_dependency "rake", "~> 10.0"
25
- spec.add_development_dependency "rspec", "~> 3.3.0"
26
+ spec.add_development_dependency "rspec", "~> 3.3"
26
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: technologist
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
  - Alexis Reigel
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-10-23 00:00:00.000000000 Z
11
+ date: 2015-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rugged
@@ -58,15 +58,16 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 3.3.0
61
+ version: '3.3'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 3.3.0
69
- description: ''
68
+ version: '3.3'
69
+ description: Detects technologies in a repository by applying a set of rules and returning
70
+ primary and secondary frameworks.
70
71
  email:
71
72
  - mail@koffeinfrei.org
72
73
  executables: []
@@ -88,10 +89,16 @@ files:
88
89
  - lib/technologist/frameworks.yml
89
90
  - lib/technologist/git_repository.rb
90
91
  - lib/technologist/repository.rb
92
+ - lib/technologist/rules/directory_presence_rule.rb
93
+ - lib/technologist/rules/file_content_rule.rb
94
+ - lib/technologist/rules/file_presence_rule.rb
95
+ - lib/technologist/rules/gem_rule.rb
96
+ - lib/technologist/rules/rule.rb
91
97
  - lib/technologist/version.rb
92
98
  - technologist.gemspec
93
99
  homepage: https://github.com/github/koffeinfrei/linguist
94
- licenses: []
100
+ licenses:
101
+ - AGPL-3.0
95
102
  metadata: {}
96
103
  post_install_message:
97
104
  rdoc_options: []