Module: BrowseEverythingHelper
- Defined in:
- app/helpers/browse_everything_helper.rb
Instance Method Summary collapse
- #file_size_to_human_size(file_size) ⇒ Object
- #is_acceptable?(file) ⇒ TrueClass, FalseClass
-
#mime_match?(value, matcher) ⇒ TrueClass, FalseClass
Extracted from Rack::Mime 1.5.2 for use with earlier versions of Rack/Rails.
Instance Method Details
#file_size_to_human_size(file_size) ⇒ Object
24 25 26 |
# File 'app/helpers/browse_everything_helper.rb', line 24 def file_size_to_human_size(file_size) "#{file_size} bytes" end |
#is_acceptable?(file) ⇒ TrueClass, FalseClass
17 18 19 20 21 22 |
# File 'app/helpers/browse_everything_helper.rb', line 17 def is_acceptable?(file) acceptable = params[:accept] || '*/*' acceptable_types = acceptable.split(/,\s*/) acceptable_types << 'application/x-directory' acceptable_types.any? { |type| mime_match?(file.type, type) } end |
#mime_match?(value, matcher) ⇒ TrueClass, FalseClass
Extracted from Rack::Mime 1.5.2 for use with earlier versions of Rack/Rails
8 9 10 11 12 13 |
# File 'app/helpers/browse_everything_helper.rb', line 8 def mime_match?(value, matcher) v1, v2 = value.split('/', 2) m1, m2 = matcher.split('/', 2) return false if m1 != '*' && v1 != m1 m2.nil? || m2 == '*' || m2 == v2 end |