Class: Bike::File
Overview
- Author
-
Akira FUNAI
- Copyright
-
Copyright © 2009 Akira FUNAI
Direct Known Subclasses
Constant Summary
Constants inherited from Field
Instance Attribute Summary
Attributes inherited from Field
Instance Method Summary collapse
- #body ⇒ Object
- #commit(type = :temp) ⇒ Object
- #errors ⇒ Object
-
#initialize(meta = {}) ⇒ File
constructor
A new instance of File.
- #meta_path ⇒ Object
- #meta_persistent_name ⇒ Object
- #meta_persistent_sd ⇒ Object
- #meta_tmp_path ⇒ Object
Methods inherited from Field
#[], #[]=, #create, #default_action, #delete, #empty?, #find_ancestor, #get, h, #inspect, instance, #item, #load, #load_default, #meta_admins, #meta_client, #meta_folder, #meta_full_name, #meta_group, #meta_name, #meta_owner, #meta_owners, #meta_roles, #meta_sd, #meta_short_name, #pending?, #permit?, #post, #update, #val, #valid?, #workflow
Methods included from I18n
_, bindtextdomain, domain, domain=, find_msg, lang, lang=, merge_msg!, msg, n_, parse_msg, po_dir, po_dir=
Constructor Details
#initialize(meta = {}) ⇒ File
Returns a new instance of File.
8 9 10 11 12 |
# File 'lib/scalar/file.rb', line 8 def initialize( = {}) [:options].collect! {|i| i.downcase } if [:options] [:size] = $&.to_i if [:tokens] && [:tokens].first =~ /^\d+$/ super end |
Instance Method Details
#body ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/scalar/file.rb', line 37 def body raise Bike::Error::Forbidden unless permit? :read if ps = my[:persistent_sd] @body ||= ps.storage.val my[:persistent_name] end @body end |
#commit(type = :temp) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/scalar/file.rb', line 65 def commit(type = :temp) if type == :temp && @action == :delete @val = {} @body = nil elsif type == :persistent && ps = my[:persistent_sd] case @action when :create, :update, nil ps.storage.store( my[:persistent_name], @body, val['basename'][/\.([\w\.]+)$/, 1] || 'bin' ) if @body && valid? when :delete ps.storage.delete my[:persistent_name] end end super end |
#errors ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/scalar/file.rb', line 46 def errors if ( val['basename'] && my[:options].is_a?(::Array) && !my[:options].empty? && !my[:options].include?(val['basename'].to_s[/\.([\w\.]+)$/i, 1].downcase) ) [_('wrong file type: should be %{types}') % {:types => my[:options].join('/')}] elsif (my[:max].to_i > 0) && (val['size'].to_i > my[:max]) [_('too large: %{max} bytes maximum') % {:max => my[:max]}] elsif (my[:min].to_i == 1) && val['size'].to_i < 1 [_('mandatory')] elsif (my[:min].to_i > 0) && (val['size'].to_i < my[:min]) [_('too small: %{min} bytes minimum') % {:min => my[:min]}] else [] end end |
#meta_path ⇒ Object
14 15 16 |
# File 'lib/scalar/file.rb', line 14 def my[:full_name].gsub('-', '/') end |
#meta_persistent_name ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/scalar/file.rb', line 26 def f = my[:parent] ps = my[:persistent_sd] name = my[:id] until f == ps name = "#{f[:id]}-#{name}" f = f[:parent] end name end |