corser 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f1015a8ab8b64c3348241abfd317f35b0c38c134
4
+ data.tar.gz: b575c1f101864c5f971286594c98d82ca1635646
5
+ SHA512:
6
+ metadata.gz: 6119f1b4694b963934e909afac84151d9311825fb76f8240165095ef29c34dda4c6414f35010d4f5b60152a25859b06ddfcd4b47ab58316f6e52b526b81f4d46
7
+ data.tar.gz: c74de559c536024350fcd3b071ec41429d5219d7ff0d20d7cedcd973b001024afaaf5837f054feea8a5c48a072993a49c3c5d51a744e8183c339620b4a667c46
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /neural_net/tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in corser.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Corser
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/corser`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'corser'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install corser
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/corser.
36
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "corser"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/corser.gemspec ADDED
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'corser/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "corser"
8
+ spec.version = Corser::VERSION
9
+ spec.authors = ["silver"]
10
+ spec.email = ["max.s@active-bridge.com"]
11
+
12
+ spec.summary = ''
13
+ spec.description = ''
14
+ spec.homepage = ''
15
+ spec.license = ''
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_runtime_dependency "bundler"
34
+ spec.add_runtime_dependency "rake", "~> 10.0"
35
+ spec.add_runtime_dependency "rspec", "~> 3.0"
36
+ spec.add_runtime_dependency "rubocop", "~> 0.41.1"
37
+ spec.add_runtime_dependency "activesupport"
38
+ end
@@ -0,0 +1,3 @@
1
+ module Corser
2
+ VERSION = "0.1.3"
3
+ end
data/lib/corser.rb ADDED
@@ -0,0 +1,129 @@
1
+ require 'corser/version'
2
+ require 'rubocop'
3
+ require 'active_support/core_ext/enumerable'
4
+ require 'csv'
5
+
6
+ module Corser
7
+ module Parser
8
+ class Ruby
9
+ attr_reader :parsed_data, :raw_code, :all_lines_size
10
+
11
+ RUBY_VER = 2.3
12
+
13
+ KEYWORDS_LIST = %w(__ENCODING__ __LINE__ __FILE__ BEGIN END alias and begin break case defined? do
14
+ else elsif ensure false for if in module next nil not or redo rescue retry return self
15
+ super then true undef unless until when while yield
16
+ )
17
+
18
+ CSV_ROW_LIST = %w{size_of_all_keywords tenary_count if_else_deviation
19
+ comments_size function_count avg_depth_of_lines standart_line_deviation
20
+ single_quotes_size double_quotes_size same_developer}
21
+
22
+ def initialize(file_path)
23
+ @parsed_data = RuboCop::ProcessedSource.send(:from_file, file_path, RUBY_VER)
24
+ @raw_code = truncate_comments(parsed_data.raw_source, parsed_data.comments)
25
+ @all_lines_size = parsed_data.lines.size
26
+ end
27
+
28
+ def save_to_csv(same_developer = 1, *methods_list, file_path)
29
+ if methods_list.empty?
30
+ methods_list = CSV_ROW_LIST
31
+ else
32
+ methods_list << "same_developer"
33
+ end
34
+ CSV.open(file_path, "ab") { |csv| csv << methods_list } unless File.exists?(file_path)
35
+
36
+ data = []
37
+ methods_list.each do |method|
38
+ data << eval(method).round(2)
39
+ end
40
+
41
+ CSV.open(file_path, "ab") { |csv| csv << data }
42
+ end
43
+
44
+ def size_of_all_keywords
45
+ raw_code.scan(/\b#{KEYWORDS_LIST.join('\b|\b')}\b/).size.to_f / all_lines_size
46
+ end
47
+
48
+ def size_of_each_keyword
49
+ sum = 0
50
+ word_counter = 0
51
+ KEYWORDS_LIST.each do |keyword|
52
+ word_counter = raw_code.scan(/(\b(#{keyword})\b)/).size.to_f
53
+ sum = sum + word_counter
54
+ p "#{keyword}: #{word_counter}" if word_counter > 0
55
+ end
56
+
57
+ sum
58
+ end
59
+
60
+ def comments_size
61
+ parsed_data.comments.size.to_f / all_lines_size
62
+ end
63
+
64
+ def avg_all_lines
65
+ (parsed_data.lines.map(&:length).sum - comments_length).to_f / (all_lines_size - comments_size)
66
+ end
67
+
68
+ def function_count
69
+ parsed_data.ast&.each_node(:def, :defs).count.to_f / all_lines_size
70
+ end
71
+
72
+ def tenary_count
73
+ raw_code.scan(/\s\?|\bif\b/).size.to_f / all_lines_size
74
+ end
75
+
76
+ def if_else_deviation
77
+ ifs = raw_code.scan(/\bif\b/).size
78
+ elses = raw_code.scan(/\belse\b/).size
79
+ return 0.00 if ifs == 0
80
+ (elses / ifs).to_f
81
+ end
82
+
83
+ def empty_lines_size
84
+ parsed_data.ast&.each_node(:def, :defs).map { |m| m.source.scan(/^[\s]*?$\n/).size.to_f }
85
+ end
86
+
87
+ def all_empty_lines_size
88
+ (parsed_data.lines.select { |l| l.empty? }.size - 1).to_f / all_lines_size
89
+ end
90
+
91
+ def standart_line_deviation
92
+ (raw_code.lines.map(&:length).max - 1).to_f / avg_all_lines
93
+ end
94
+
95
+ def depth_of_lines
96
+ parsed_data.lines.map { |l| l.scan(/^\s*/) }.flatten.map(&:length)
97
+ end
98
+
99
+ def max_depth_of_lines
100
+ depth_of_lines.max
101
+ end
102
+
103
+ def avg_depth_of_lines
104
+ depth_of_lines.instance_eval { reduce(:+) / size.to_f }
105
+ end
106
+
107
+ def single_quotes_size
108
+ (raw_code.scan(/'.*'/).size.to_f / avg_all_lines).to_f
109
+ end
110
+
111
+ def double_quotes_size
112
+ (raw_code.scan(/".*"/).size.to_f / avg_all_lines).to_f
113
+ end
114
+
115
+ private
116
+
117
+ def truncate_comments(code, comments)
118
+ comments.each { |c| code.slice! c.text }
119
+ code
120
+ end
121
+
122
+ def comments_length
123
+ sum = 0
124
+ parsed_data.comments.each { |comment| sum = sum + comment.text.length }
125
+ sum
126
+ end
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,41 @@
1
+ class Ability
2
+ include CanCan::Ability
3
+
4
+ def initialize(user)
5
+ # See the wiki for details:
6
+ # https://github.com/ryanb/cancan/wiki/Defining-Abilities
7
+
8
+ if user
9
+ can :manage, :all
10
+ cannot :publish, Recommendation
11
+
12
+ cannot :create, Recommendation do |recommendation|
13
+ business = recommendation.business
14
+
15
+ business.user == user || user.recommendations.for_business(business).any?
16
+ end
17
+
18
+ cannot :claim, Recommendation do |recommendation|
19
+ user.owner_for?(recommendation) || user.claim_on?(recommendation.business)
20
+ end
21
+
22
+ can :publish, Recommendation do |recommendation|
23
+ can_owner_publish = recommendation.business.user == user && !recommendation.edited?
24
+ can_user_publish = recommendation.user == user && recommendation.edited?
25
+
26
+ !recommendation.published? && (can_owner_publish || can_user_publish)
27
+ end
28
+
29
+ cannot :claim, Share do |share|
30
+ user.owner_for?(share) || user.claim_on?(share.business)
31
+ end
32
+
33
+ cannot :redeem, Product do |product|
34
+ !product.redeemable_for?(user)
35
+ end
36
+ else
37
+ can :read, :all
38
+ can :claim, Share
39
+ end
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: corser
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - silver
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-03-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.41.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.41.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: activesupport
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: ''
84
+ email:
85
+ - max.s@active-bridge.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - Gemfile
93
+ - README.md
94
+ - Rakefile
95
+ - bin/console
96
+ - bin/setup
97
+ - corser.gemspec
98
+ - lib/corser.rb
99
+ - lib/corser/version.rb
100
+ - species/ability.rb
101
+ homepage: ''
102
+ licenses:
103
+ - ''
104
+ metadata:
105
+ allowed_push_host: https://rubygems.org
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.5.1
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: ''
126
+ test_files: []