Class: CodeStats::Project
- Inherits:
-
Object
- Object
- CodeStats::Project
- Defined in:
- lib/code_stats/project.rb
Constant Summary collapse
- AVAILIABLE_OPTIONS =
[:spec_filter, :skip_filter]
- DEFAUL_SPEC_FILTER =
/\/tests?\/|\/specs?\//
- DEFAUL_SKIP_FILTER =
/\/docs?\/|\/(s|ex)amples?\/|\/guides?\/|\/.git\/|\/tmp\/|\/old\/|database\.php|\/vendor\//
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#skip_filter ⇒ Object
readonly
Returns the value of attribute skip_filter.
-
#sources ⇒ Object
readonly
Returns the value of attribute sources.
-
#spec_filter ⇒ Object
readonly
Returns the value of attribute spec_filter.
-
#specs ⇒ Object
readonly
Returns the value of attribute specs.
-
#unknown_extensions ⇒ Object
readonly
Returns the value of attribute unknown_extensions.
Instance Method Summary collapse
- #analyze! ⇒ Object
- #files(&b) ⇒ Object
-
#initialize(path, options = {}) ⇒ Project
constructor
A new instance of Project.
Constructor Details
#initialize(path, options = {}) ⇒ Project
Returns a new instance of Project.
9 10 11 12 13 14 15 |
# File 'lib/code_stats/project.rb', line 9 def initialize path, = {} @path, @name = path, path.to_entry.name . *AVAILIABLE_OPTIONS @spec_filter = .include?(:spec_filter) ? [:spec_filter] : DEFAUL_SPEC_FILTER @skip_filter = .include?(:skip_filter) ? [:skip_filter] : DEFAUL_SKIP_FILTER clear end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
2 3 4 |
# File 'lib/code_stats/project.rb', line 2 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
2 3 4 |
# File 'lib/code_stats/project.rb', line 2 def path @path end |
#skip_filter ⇒ Object (readonly)
Returns the value of attribute skip_filter.
2 3 4 |
# File 'lib/code_stats/project.rb', line 2 def skip_filter @skip_filter end |
#sources ⇒ Object (readonly)
Returns the value of attribute sources.
3 4 5 |
# File 'lib/code_stats/project.rb', line 3 def sources @sources end |
#spec_filter ⇒ Object (readonly)
Returns the value of attribute spec_filter.
2 3 4 |
# File 'lib/code_stats/project.rb', line 2 def spec_filter @spec_filter end |
#specs ⇒ Object (readonly)
Returns the value of attribute specs.
3 4 5 |
# File 'lib/code_stats/project.rb', line 3 def specs @specs end |
#unknown_extensions ⇒ Object (readonly)
Returns the value of attribute unknown_extensions.
2 3 4 |
# File 'lib/code_stats/project.rb', line 2 def unknown_extensions @unknown_extensions end |
Instance Method Details
#analyze! ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/code_stats/project.rb', line 28 def analyze! clear files do |file| ext = file.extension.to_sym if CodeStats.know?(ext) warn("file #{file} is too big, skipping") and next if file.size > CodeStats.file_size_limit script = CodeStats.parse file.read.force_utf8_encoding, ext source?(file) ? sources.add(script) : specs.add(script) else unknown_extensions << ext unless unknown_extensions.include? ext end end end |
#files(&b) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/code_stats/project.rb', line 17 def files &b files = [] path.to_dir.files '**/*.*' do |file| next if skip?(file) b ? b.call(file) : files.push(file) end b ? nil : files end |