Class: CodeStats::Project
- Inherits:
-
Object
- Object
- CodeStats::Project
- Defined in:
- lib/code_stats/project.rb
Constant Summary collapse
- AVAILIABLE_OPTIONS =
[:specs_filter, :skip_filter]
- DEFAUL_SPEC_FILTER =
/\/tests?\/|\/specs?\//
- DEFAUL_SKIP_FILTER =
/\/docs?\/|\/(s|ex)amples?\/|\/guides?\/|\/.git\/|\/tmp\/|database\.php/
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.
-
#specs ⇒ Object
readonly
Returns the value of attribute specs.
-
#specs_filter ⇒ Object
readonly
Returns the value of attribute specs_filter.
-
#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 @specs_filter = .include?(:specs_filter) ? [:specs_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 |
#specs ⇒ Object (readonly)
Returns the value of attribute specs.
3 4 5 |
# File 'lib/code_stats/project.rb', line 3 def specs @specs end |
#specs_filter ⇒ Object (readonly)
Returns the value of attribute specs_filter.
2 3 4 |
# File 'lib/code_stats/project.rb', line 2 def specs_filter @specs_filter 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 |