Class: RailsWayback::ViewSource
- Inherits:
-
Object
- Object
- RailsWayback::ViewSource
- Defined in:
- lib/rails_wayback/view_source.rb
Overview
Materialises the view/asset directories of a given git ref into a sandbox under tmp/, so a controller can prepend that sandbox as a view path and render the historical templates.
Only the directories listed in configuration.view_paths and
configuration.asset_paths are pulled from the ref. Nothing is
executed, and the developer's real files are never mutated.
Constant Summary collapse
- MATERIALIZATION_VERSION =
Bumped whenever the materialization format changes so stale sandboxes from earlier gem versions get rebuilt instead of being reused.
"2"
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#git ⇒ Object
readonly
Returns the value of attribute git.
Instance Method Summary collapse
- #cleanup! ⇒ Object
-
#initialize(configuration: RailsWayback.configuration, git: RailsWayback::Git.new) ⇒ ViewSource
constructor
A new instance of ViewSource.
- #materialize(ref) ⇒ Object
- #view_root_for(ref) ⇒ Object
Constructor Details
#initialize(configuration: RailsWayback.configuration, git: RailsWayback::Git.new) ⇒ ViewSource
Returns a new instance of ViewSource.
23 24 25 26 |
# File 'lib/rails_wayback/view_source.rb', line 23 def initialize(configuration: RailsWayback.configuration, git: RailsWayback::Git.new) @configuration = configuration @git = git end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
21 22 23 |
# File 'lib/rails_wayback/view_source.rb', line 21 def configuration @configuration end |
#git ⇒ Object (readonly)
Returns the value of attribute git.
21 22 23 |
# File 'lib/rails_wayback/view_source.rb', line 21 def git @git end |
Instance Method Details
#cleanup! ⇒ Object
45 46 47 |
# File 'lib/rails_wayback/view_source.rb', line 45 def cleanup! FileUtils.rm_rf(configuration.refs_cache_path) end |
#materialize(ref) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rails_wayback/view_source.rb', line 28 def materialize(ref) sha = git.resolve_ref(ref) target = configuration.refs_cache_path.join(sha) return target if fresh?(target, sha) FileUtils.rm_rf(target) FileUtils.mkdir_p(target) tracked_paths.each { |path| extract_path(sha, path, target) } write_marker(target, sha) target end |
#view_root_for(ref) ⇒ Object
40 41 42 43 |
# File 'lib/rails_wayback/view_source.rb', line 40 def view_root_for(ref) target = materialize(ref) configuration.view_paths.map { |p| target.join(p) }.select(&:directory?) end |