Module: ViewMapper::PaperclipView
- Defined in:
- lib/view_mapper/views/paperclip/paperclip_view.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_model_actions(m) ⇒ Object
- #attachments ⇒ Object
- #is_model_dependency_action(action) ⇒ Object
- #manifest ⇒ Object
- #paperclip_installed ⇒ Object
- #parse_attachments_from_param ⇒ Object
- #source_roots_for_view ⇒ Object
- #validate ⇒ Object
- #validate_attachment(attachment) ⇒ Object
- #validate_attachments ⇒ Object
Class Method Details
.source_root ⇒ Object
4 5 6 |
# File 'lib/view_mapper/views/paperclip/paperclip_view.rb', line 4 def self.source_root File.(File.dirname(__FILE__) + "/templates") end |
Instance Method Details
#add_model_actions(m) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/view_mapper/views/paperclip/paperclip_view.rb', line 22 def add_model_actions(m) m.directory(File.join('test/fixtures', class_path)) m.template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb") m.template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_test.rb") unless [:skip_fixture] m.template 'fixtures.yml', File.join('test/fixtures', "#{table_name}.yml") end unless [:skip_migration] m.migration_template 'migration.rb', 'db/migrate', :assigns => { :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}" }, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}" end end |
#attachments ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/view_mapper/views/paperclip/paperclip_view.rb', line 41 def if view_param elsif view_only? model. else [] end end |
#is_model_dependency_action(action) ⇒ Object
37 38 39 |
# File 'lib/view_mapper/views/paperclip/paperclip_view.rb', line 37 def is_model_dependency_action(action) action[0] == :dependency && action[1].include?('model') end |
#manifest ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/view_mapper/views/paperclip/paperclip_view.rb', line 12 def manifest m = super.edit do |action| action unless is_model_dependency_action(action) || !valid end unless view_only? || !valid add_model_actions(m) end m end |
#paperclip_installed ⇒ Object
89 90 91 92 |
# File 'lib/view_mapper/views/paperclip/paperclip_view.rb', line 89 def paperclip_installed ActiveRecord::Base.methods.include?('has_attached_file') || ActiveRecord::Base.methods.include?(:has_attached_file) end |
#parse_attachments_from_param ⇒ Object
51 52 53 |
# File 'lib/view_mapper/views/paperclip/paperclip_view.rb', line 51 def view_param.split(',') end |
#source_roots_for_view ⇒ Object
8 9 10 |
# File 'lib/view_mapper/views/paperclip/paperclip_view.rb', line 8 def source_roots_for_view [ PaperclipView.source_root, File.(source_root), File.join(self.class.lookup('model').path, 'templates') ] end |
#validate ⇒ Object
55 56 57 58 |
# File 'lib/view_mapper/views/paperclip/paperclip_view.rb', line 55 def validate @valid = @valid &&= super end |
#validate_attachment(attachment) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/view_mapper/views/paperclip/paperclip_view.rb', line 76 def () if view_only? if !model.() logger.error "Attachment '#{attachment}' does not exist." return false elsif !model.() logger.error model.error return false end end true end |
#validate_attachments ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/view_mapper/views/paperclip/paperclip_view.rb', line 60 def if !paperclip_installed logger.error "The Paperclip plugin does not appear to be installed." return false elsif .empty? if view_only? logger.warning "No paperclip attachments exist on the specified class." else logger.warning "No paperclip attachments specified." end return false else !.detect { |a| !(a) } end end |