Class: SpecViews::Directory
- Inherits:
-
Object
- Object
- SpecViews::Directory
- Defined in:
- app/models/spec_views/directory.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #basename ⇒ Object
- #binary? ⇒ Boolean
- #challenger? ⇒ Boolean
- #challenger_path ⇒ Object
- #champion_html ⇒ Object
- #champion_path ⇒ Object
- #content_type ⇒ Object
- #controller_name ⇒ Object
- #delete! ⇒ Object
- #description ⇒ Object
- #description_tail ⇒ Object
-
#initialize(path, content_type = nil) ⇒ Directory
constructor
A new instance of Directory.
- #last_run ⇒ Object
- #last_run_path ⇒ Object
- #meta ⇒ Object
- #meta_path ⇒ Object
- #method ⇒ Object
- #name ⇒ Object
- #spec_type ⇒ Object
- #to_param ⇒ Object
- #write_challenger(content) ⇒ Object
- #write_last_run(run_time) ⇒ Object
- #write_meta(description, spec_type, content_type) ⇒ Object
Constructor Details
#initialize(path, content_type = nil) ⇒ Directory
Returns a new instance of Directory.
12 13 14 15 |
# File 'app/models/spec_views/directory.rb', line 12 def initialize(path, content_type = nil) @path = path @content_type = ActiveSupport::StringInquirer.new(content_type.to_s) if content_type end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'app/models/spec_views/directory.rb', line 5 def path @path end |
Class Method Details
.for_description(description, content_type: :html) ⇒ Object
7 8 9 10 |
# File 'app/models/spec_views/directory.rb', line 7 def self.for_description(description, content_type: :html) dir_name = description.strip.gsub(/[^0-9A-Za-z.\-]/, '_').gsub('__', '_') new(Rails.root.join(Rails.configuration.spec_views.directory, dir_name), content_type) end |
Instance Method Details
#basename ⇒ Object
17 18 19 |
# File 'app/models/spec_views/directory.rb', line 17 def basename path.basename end |
#binary? ⇒ Boolean
107 108 109 |
# File 'app/models/spec_views/directory.rb', line 107 def binary? content_type.pdf? end |
#challenger? ⇒ Boolean
59 60 61 |
# File 'app/models/spec_views/directory.rb', line 59 def challenger? File.file?(challenger_path) end |
#challenger_path ⇒ Object
55 56 57 |
# File 'app/models/spec_views/directory.rb', line 55 def challenger_path path.join("challenger.#{file_extension}") end |
#champion_html ⇒ Object
49 50 51 52 53 |
# File 'app/models/spec_views/directory.rb', line 49 def champion_html File.read(champion_path) rescue Errno::ENOENT nil end |
#champion_path ⇒ Object
45 46 47 |
# File 'app/models/spec_views/directory.rb', line 45 def champion_path path.join("view.#{file_extension}") end |
#content_type ⇒ Object
99 100 101 102 103 104 105 |
# File 'app/models/spec_views/directory.rb', line 99 def content_type @content_type ||= begin ct = 'html' ct = [3] if && [3].present? ActiveSupport::StringInquirer.new(ct) end end |
#controller_name ⇒ Object
29 30 31 |
# File 'app/models/spec_views/directory.rb', line 29 def controller_name splitted_description.first.gsub(/Controller(_.*)$/, 'Controller').gsub(/Controller$/, '').gsub('_', '::') end |
#delete! ⇒ Object
41 42 43 |
# File 'app/models/spec_views/directory.rb', line 41 def delete! FileUtils.remove_dir(path) end |
#description ⇒ Object
87 88 89 90 91 |
# File 'app/models/spec_views/directory.rb', line 87 def description [0] rescue Errno::ENOENT name end |
#description_tail ⇒ Object
37 38 39 |
# File 'app/models/spec_views/directory.rb', line 37 def description_tail splitted_description.third end |
#last_run ⇒ Object
120 121 122 123 124 |
# File 'app/models/spec_views/directory.rb', line 120 def last_run Time.zone.parse(File.read(last_run_path).strip) rescue Errno::ENOENT Time.zone.at(0) end |
#last_run_path ⇒ Object
111 112 113 |
# File 'app/models/spec_views/directory.rb', line 111 def last_run_path path.join('last_run.txt') end |
#meta ⇒ Object
83 84 85 |
# File 'app/models/spec_views/directory.rb', line 83 def @meta ||= File.read().lines.map(&:strip) end |
#meta_path ⇒ Object
68 69 70 |
# File 'app/models/spec_views/directory.rb', line 68 def path.join('meta.txt') end |
#method ⇒ Object
33 34 35 |
# File 'app/models/spec_views/directory.rb', line 33 def method splitted_description.second[0, 4] end |
#name ⇒ Object
25 26 27 |
# File 'app/models/spec_views/directory.rb', line 25 def name basename end |
#spec_type ⇒ Object
93 94 95 96 97 |
# File 'app/models/spec_views/directory.rb', line 93 def spec_type ActiveSupport::StringInquirer.new([2]) rescue Errno::ENOENT :response end |
#to_param ⇒ Object
21 22 23 |
# File 'app/models/spec_views/directory.rb', line 21 def to_param basename.to_s end |
#write_challenger(content) ⇒ Object
63 64 65 66 |
# File 'app/models/spec_views/directory.rb', line 63 def write_challenger(content) FileUtils.mkdir_p(path) File.open(challenger_path, binary? ? 'wb' : 'w') { |f| f.write(content) } end |
#write_last_run(run_time) ⇒ Object
115 116 117 118 |
# File 'app/models/spec_views/directory.rb', line 115 def write_last_run(run_time) FileUtils.mkdir_p(path) File.write(last_run_path, run_time.to_s) end |
#write_meta(description, spec_type, content_type) ⇒ Object
72 73 74 75 76 77 78 79 80 81 |
# File 'app/models/spec_views/directory.rb', line 72 def (description, spec_type, content_type) FileUtils.mkdir_p(path) lines = [ description.to_s.gsub("\n", ' '), '', spec_type.to_s, content_type.to_s ] File.write(, lines.join("\n")) end |