Class: Videos::Videos
- Inherits:
-
Object
- Object
- Videos::Videos
- Defined in:
- lib/videos/videos.rb,
lib/videos/videos_package.rb
Instance Attribute Summary collapse
-
#root_path ⇒ Object
readonly
Returns the value of attribute root_path.
-
#videos_path ⇒ Object
readonly
Returns the value of attribute videos_path.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(root_path) ⇒ Videos
constructor
A new instance of Videos.
- #pathname_to_url(path, relative_from) ⇒ Object
- #update ⇒ Object
- #update_app ⇒ Object
- #url_to_pathname(url) ⇒ Object
Constructor Details
Instance Attribute Details
#root_path ⇒ Object (readonly)
Returns the value of attribute root_path.
2 3 4 |
# File 'lib/videos/videos.rb', line 2 def root_path @root_path end |
#videos_path ⇒ Object (readonly)
Returns the value of attribute videos_path.
3 4 5 |
# File 'lib/videos/videos.rb', line 3 def videos_path @videos_path end |
Class Method Details
.gem_path ⇒ Object
16 17 18 |
# File 'lib/videos/videos.rb', line 16 def self.gem_path Pathname.new(__FILE__).dirname.parent.parent end |
.load_json(path) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/videos/videos_package.rb', line 35 def self.load_json(path) if File.exists?(path) JSON.parse(File.read(path)) else nil end end |
.save_json(path, data) ⇒ Object
43 44 45 |
# File 'lib/videos/videos_package.rb', line 43 def self.save_json(path, data) File.open(path, "w") { |f| f << data.to_json } end |
Instance Method Details
#pathname_to_url(path, relative_from) ⇒ Object
5 6 7 8 |
# File 'lib/videos/videos.rb', line 5 def pathname_to_url(path, relative_from) url = path.relative_path_from(relative_from) (url.dirname + URI.escape(url.basename.to_s, URI::REGEXP::PATTERN::RESERVED).force_encoding("utf-8")).to_s end |
#update ⇒ Object
9 10 11 12 13 |
# File 'lib/videos/videos_package.rb', line 9 def update videos_path.mkdir unless File.exists?(videos_path) update_app Videos::Update.new(self) end |
#update_app ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/videos/videos_package.rb', line 15 def update_app dev = ENV["VIDEOS_ENV"] == "development" app_children_paths.each do |file| videos_file = videos_path + file.basename FileUtils.rm_rf(videos_file, :verbose => dev) end if dev app_children_paths.each do |file| videos_file = videos_path + file.basename FileUtils.ln_sf(file, videos_file, :verbose => dev) end else FileUtils.cp_r(Videos::Videos.gem_path + "app/.", videos_path, :verbose => dev) end FileUtils.chmod_R(0755, videos_path, :verbose => dev) end |
#url_to_pathname(url) ⇒ Object
10 11 12 13 14 |
# File 'lib/videos/videos.rb', line 10 def url_to_pathname(url) path = Addressable::URI.unencode_component(url.normalized_path) path.gsub!(/^\//, "") #Make relative, if we allow mounting at a different root URL this will need to remove the root instead of just '/' root_path + path end |