Class: Codeqa::Sourcefile
- Inherits:
-
Object
- Object
- Codeqa::Sourcefile
- Defined in:
- lib/codeqa/sourcefile.rb
Constant Summary collapse
- BINARY_PATTERN =
/\.(swf|jpg|png|gif|pdf|xls|zip|eot|woff|ttf|mo|so|gem)$/
- ERB_PATTERN =
/\.(erb|rhtml|text\.html|text\.plain)$/
- HTML_PATTERN =
/\.(rhtml|html|text\.html)/
- RUBY_PATTERN =
/\.(rb|gemspec)$/
- RUBY_NAMES =
%w(Guardfile Gemfile Rakefile config.ru)
- SPEC_PATTERN =
/_spec\.rb$/
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Instance Method Summary collapse
- #binary? ⇒ Boolean
- #content ⇒ Object
- #erb? ⇒ Boolean
- #exist? ⇒ Boolean
- #html? ⇒ Boolean
-
#initialize(filename, content = nil) ⇒ Sourcefile
constructor
A new instance of Sourcefile.
- #ruby? ⇒ Boolean
- #spec? ⇒ Boolean
- #text? ⇒ Boolean
Constructor Details
#initialize(filename, content = nil) ⇒ Sourcefile
Returns a new instance of Sourcefile.
10 11 12 13 14 |
# File 'lib/codeqa/sourcefile.rb', line 10 def initialize(filename, content=nil) @filename = filename @content = content # ensure_file end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
16 17 18 |
# File 'lib/codeqa/sourcefile.rb', line 16 def filename @filename end |
Instance Method Details
#binary? ⇒ Boolean
30 31 32 |
# File 'lib/codeqa/sourcefile.rb', line 30 def binary? @binary ||= !!(filename =~ BINARY_PATTERN) end |
#content ⇒ Object
18 19 20 |
# File 'lib/codeqa/sourcefile.rb', line 18 def content @content ||= File.read(filename) end |
#erb? ⇒ Boolean
38 39 40 |
# File 'lib/codeqa/sourcefile.rb', line 38 def erb? @erb ||= !!(filename =~ ERB_PATTERN) end |
#exist? ⇒ Boolean
22 23 24 |
# File 'lib/codeqa/sourcefile.rb', line 22 def exist? File.exist?(filename) end |
#html? ⇒ Boolean
42 43 44 |
# File 'lib/codeqa/sourcefile.rb', line 42 def html? @html ||= !!(filename =~ HTML_PATTERN) && !ruby? end |
#ruby? ⇒ Boolean
34 35 36 |
# File 'lib/codeqa/sourcefile.rb', line 34 def ruby? @ruby ||= (RUBY_NAMES.include?(filename) || !!(filename =~ RUBY_PATTERN)) end |
#spec? ⇒ Boolean
46 47 48 |
# File 'lib/codeqa/sourcefile.rb', line 46 def spec? @spec ||= !!(filename =~ SPEC_PATTERN) end |
#text? ⇒ Boolean
26 27 28 |
# File 'lib/codeqa/sourcefile.rb', line 26 def text? !binary? end |