morse_assetable 0.2.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/morse_assetable.rb +145 -143
 - data/lib/morse_assetable/version.rb +1 -1
 - data/morse_assetable-0.2.2.gem +0 -0
 - metadata +2 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: cf85029cd3597c4c7c633860ca9e489081ea2a7f
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: a08b4e73e0a6a50e7e1bb04c709c575c2fec2976
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 2e5ba0fd0dece34252779e57f0cb7d6aeec49228d35945ccd35f1048f3840b9602b91f89e22fb2b4de792e0e71884eaa9e266322d2501c7eb403c0ed5be11351
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: b378d37a3be204c2fd30fc7e174a84bbab3c945653fa4328ec2b7b798b4a8e8447796c51dfbef778e7127e939aa606d35bc1b70dd74bc9f49001563bce25d627
         
     | 
    
        data/lib/morse_assetable.rb
    CHANGED
    
    | 
         @@ -1,180 +1,182 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # MorseAssetable
         
     | 
| 
       1 
2 
     | 
    
         
             
            require "morse_assetable/version"
         
     | 
| 
       2 
     | 
    
         
            -
            module  
     | 
| 
       3 
     | 
    
         
            -
               
     | 
| 
       4 
     | 
    
         
            -
                 
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
      
 3 
     | 
    
         
            +
            module MorseAssetable # rubocop:disable Metrics/ModuleLength
         
     | 
| 
      
 4 
     | 
    
         
            +
              module ViewHelpers
         
     | 
| 
      
 5 
     | 
    
         
            +
                def asset_input(f, i, bn = nil)
         
     | 
| 
      
 6 
     | 
    
         
            +
                  return multiple_assets(i, f) unless bn
         
     | 
| 
      
 7 
     | 
    
         
            +
                  asset = i.send(bn)
         
     | 
| 
      
 8 
     | 
    
         
            +
                  render partial: 'cms/assets/partials/asset',
         
     | 
| 
      
 9 
     | 
    
         
            +
                         locals: { asset: asset,
         
     | 
| 
      
 10 
     | 
    
         
            +
                                   base_name: bn,
         
     | 
| 
      
 11 
     | 
    
         
            +
                                   f: f }
         
     | 
| 
      
 12 
     | 
    
         
            +
                end
         
     | 
| 
       11 
13 
     | 
    
         | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
      
 14 
     | 
    
         
            +
                def multiple_assets(i, f)
         
     | 
| 
      
 15 
     | 
    
         
            +
                  render partial: 'cms/assets/partials/assets',
         
     | 
| 
      
 16 
     | 
    
         
            +
                         locals: { assets: i.assets,
         
     | 
| 
      
 17 
     | 
    
         
            +
                                   f: f }
         
     | 
| 
      
 18 
     | 
    
         
            +
                end
         
     | 
| 
       17 
19 
     | 
    
         | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
      
 20 
     | 
    
         
            +
                def nice_asset(a, version = nil)
         
     | 
| 
      
 21 
     | 
    
         
            +
                  return unless a && a.attachment
         
     | 
| 
      
 22 
     | 
    
         
            +
                  image_url = a.attachment.url
         
     | 
| 
      
 23 
     | 
    
         
            +
                  image_url = a.attachment.versions[version].url if version
         
     | 
| 
      
 24 
     | 
    
         
            +
                  image_tag image_url, alt: a.alt
         
     | 
| 
      
 25 
     | 
    
         
            +
                end
         
     | 
| 
       23 
26 
     | 
    
         
             
              end
         
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
            module MorseAssetable # rubocop:disable Metrics/ModuleLength
         
     | 
| 
       27 
     | 
    
         
            -
              extend ActiveSupport::Concern
         
     | 
| 
      
 27 
     | 
    
         
            +
              module ModelHelpers
         
     | 
| 
      
 28 
     | 
    
         
            +
                extend ActiveSupport::Concern
         
     | 
| 
       28 
29 
     | 
    
         | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
      
 30 
     | 
    
         
            +
                included do
         
     | 
| 
      
 31 
     | 
    
         
            +
                  attachment_names.each do |name|
         
     | 
| 
      
 32 
     | 
    
         
            +
                    attr_accessor "#{name}_attachment".to_sym,
         
     | 
| 
      
 33 
     | 
    
         
            +
                                  "#{name}_attachment_remove".to_sym
         
     | 
| 
      
 34 
     | 
    
         
            +
                    next unless active_asset_column_names.any?
         
     | 
| 
      
 35 
     | 
    
         
            +
                    active_asset_column_names.each do |col|
         
     | 
| 
      
 36 
     | 
    
         
            +
                      attr_accessor "#{name}_attachment_#{col}".to_sym
         
     | 
| 
      
 37 
     | 
    
         
            +
                    end
         
     | 
| 
       36 
38 
     | 
    
         
             
                  end
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                  validate :process_attachments, unless: :new_record?
         
     | 
| 
      
 41 
     | 
    
         
            +
                  validate :process_multiple_attachments, unless: :new_record?
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                  after_save :process_attachments
         
     | 
| 
      
 44 
     | 
    
         
            +
                  after_save :process_multiple_attachments
         
     | 
| 
       37 
45 
     | 
    
         
             
                end
         
     | 
| 
       38 
46 
     | 
    
         | 
| 
       39 
     | 
    
         
            -
                 
     | 
| 
       40 
     | 
    
         
            -
                 
     | 
| 
      
 47 
     | 
    
         
            +
                # ClassMethods
         
     | 
| 
      
 48 
     | 
    
         
            +
                module ClassMethods
         
     | 
| 
      
 49 
     | 
    
         
            +
                  def active_asset_column_names
         
     | 
| 
      
 50 
     | 
    
         
            +
                    asset_column_names - excluded_asset_column_names
         
     | 
| 
      
 51 
     | 
    
         
            +
                  end
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
                  def asset_column_names
         
     | 
| 
      
 54 
     | 
    
         
            +
                    Asset.column_names
         
     | 
| 
      
 55 
     | 
    
         
            +
                  end
         
     | 
| 
       41 
56 
     | 
    
         | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
      
 57 
     | 
    
         
            +
                  def attachment_names
         
     | 
| 
      
 58 
     | 
    
         
            +
                    [:asset]
         
     | 
| 
      
 59 
     | 
    
         
            +
                  end
         
     | 
| 
       45 
60 
     | 
    
         | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
                  asset_column_names - excluded_asset_column_names
         
     | 
| 
       50 
     | 
    
         
            -
                end
         
     | 
| 
      
 61 
     | 
    
         
            +
                  def excluded_asset_column_names
         
     | 
| 
      
 62 
     | 
    
         
            +
                    %w(id attachment assetable_id assetable_type created_at updated_at)
         
     | 
| 
      
 63 
     | 
    
         
            +
                  end
         
     | 
| 
       51 
64 
     | 
    
         | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
      
 65 
     | 
    
         
            +
                  def multiple_attachment_names
         
     | 
| 
      
 66 
     | 
    
         
            +
                    [:downloadables]
         
     | 
| 
      
 67 
     | 
    
         
            +
                  end
         
     | 
| 
       54 
68 
     | 
    
         
             
                end
         
     | 
| 
       55 
69 
     | 
    
         | 
| 
       56 
     | 
    
         
            -
                 
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
      
 70 
     | 
    
         
            +
                private
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
                def active_asset_column_names
         
     | 
| 
      
 73 
     | 
    
         
            +
                  self.class.active_asset_column_names
         
     | 
| 
       58 
74 
     | 
    
         
             
                end
         
     | 
| 
       59 
75 
     | 
    
         | 
| 
       60 
     | 
    
         
            -
                def  
     | 
| 
       61 
     | 
    
         
            -
                   
     | 
| 
      
 76 
     | 
    
         
            +
                def add_asset_data(a)
         
     | 
| 
      
 77 
     | 
    
         
            +
                  return unless active_asset_column_names.any?
         
     | 
| 
      
 78 
     | 
    
         
            +
                  active_asset_column_names.each do |col|
         
     | 
| 
      
 79 
     | 
    
         
            +
                    add_asset_field a, col
         
     | 
| 
      
 80 
     | 
    
         
            +
                  end
         
     | 
| 
       62 
81 
     | 
    
         
             
                end
         
     | 
| 
       63 
82 
     | 
    
         | 
| 
       64 
     | 
    
         
            -
                def  
     | 
| 
       65 
     | 
    
         
            -
                   
     | 
| 
      
 83 
     | 
    
         
            +
                def add_asset_field(a, col)
         
     | 
| 
      
 84 
     | 
    
         
            +
                  n = "#{name}_attachment_#{col}".to_sym
         
     | 
| 
      
 85 
     | 
    
         
            +
                  return unless send(n).present?
         
     | 
| 
      
 86 
     | 
    
         
            +
                  a.send("#{col}=", send(n))
         
     | 
| 
       66 
87 
     | 
    
         
             
                end
         
     | 
| 
       67 
     | 
    
         
            -
              end
         
     | 
| 
       68 
88 
     | 
    
         | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
      
 89 
     | 
    
         
            +
                def attachment_name(name)
         
     | 
| 
      
 90 
     | 
    
         
            +
                  "#{name}_attachment".to_sym
         
     | 
| 
      
 91 
     | 
    
         
            +
                end
         
     | 
| 
       70 
92 
     | 
    
         | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
       73 
     | 
    
         
            -
             
     | 
| 
      
 93 
     | 
    
         
            +
                def attachment_name_remove(name)
         
     | 
| 
      
 94 
     | 
    
         
            +
                  "#{name}_attachment_remove".to_sym
         
     | 
| 
      
 95 
     | 
    
         
            +
                end
         
     | 
| 
       74 
96 
     | 
    
         | 
| 
       75 
     | 
    
         
            -
             
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
                active_asset_column_names.each do |col|
         
     | 
| 
       78 
     | 
    
         
            -
                  add_asset_field a, col
         
     | 
| 
      
 97 
     | 
    
         
            +
                def attachment_names
         
     | 
| 
      
 98 
     | 
    
         
            +
                  self.class.attachment_names
         
     | 
| 
       79 
99 
     | 
    
         
             
                end
         
     | 
| 
       80 
     | 
    
         
            -
              end
         
     | 
| 
       81 
100 
     | 
    
         | 
| 
       82 
     | 
    
         
            -
             
     | 
| 
       83 
     | 
    
         
            -
             
     | 
| 
       84 
     | 
    
         
            -
                 
     | 
| 
       85 
     | 
    
         
            -
                a.send("#{col}=", send(n))
         
     | 
| 
       86 
     | 
    
         
            -
              end
         
     | 
| 
      
 101 
     | 
    
         
            +
                def multiple_attachment_names
         
     | 
| 
      
 102 
     | 
    
         
            +
                  self.class.multiple_attachment_names
         
     | 
| 
      
 103 
     | 
    
         
            +
                end
         
     | 
| 
       87 
104 
     | 
    
         | 
| 
       88 
     | 
    
         
            -
             
     | 
| 
       89 
     | 
    
         
            -
             
     | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
      
 105 
     | 
    
         
            +
                def process_attachment(name)
         
     | 
| 
      
 106 
     | 
    
         
            +
                  n = attachment_name(name)
         
     | 
| 
      
 107 
     | 
    
         
            +
                  a = Asset.new(attachment: send(n), assetable: self)
         
     | 
| 
      
 108 
     | 
    
         
            +
                  add_asset_data(a)
         
     | 
| 
      
 109 
     | 
    
         
            +
                  if a.save
         
     | 
| 
      
 110 
     | 
    
         
            +
                    send("#{name}=", a)
         
     | 
| 
      
 111 
     | 
    
         
            +
                    send("#{n}=", nil)
         
     | 
| 
      
 112 
     | 
    
         
            +
                  else
         
     | 
| 
      
 113 
     | 
    
         
            +
                    errors.add(name, a.errors.full_messages.join(','))
         
     | 
| 
      
 114 
     | 
    
         
            +
                    false
         
     | 
| 
      
 115 
     | 
    
         
            +
                  end
         
     | 
| 
      
 116 
     | 
    
         
            +
                end
         
     | 
| 
       91 
117 
     | 
    
         | 
| 
       92 
     | 
    
         
            -
             
     | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
      
 118 
     | 
    
         
            +
                def process_attachment?(name)
         
     | 
| 
      
 119 
     | 
    
         
            +
                  n = attachment_name(name)
         
     | 
| 
      
 120 
     | 
    
         
            +
                  respond_to?(n) && send(n).present?
         
     | 
| 
      
 121 
     | 
    
         
            +
                end
         
     | 
| 
       95 
122 
     | 
    
         | 
| 
       96 
     | 
    
         
            -
             
     | 
| 
       97 
     | 
    
         
            -
             
     | 
| 
       98 
     | 
    
         
            -
             
     | 
| 
      
 123 
     | 
    
         
            +
                def process_attachment_name(name)
         
     | 
| 
      
 124 
     | 
    
         
            +
                  process_attachment(name) if process_attachment?(name)
         
     | 
| 
      
 125 
     | 
    
         
            +
                  remove_attachment(name) if remove_attachment?(name)
         
     | 
| 
      
 126 
     | 
    
         
            +
                end
         
     | 
| 
       99 
127 
     | 
    
         | 
| 
       100 
     | 
    
         
            -
             
     | 
| 
       101 
     | 
    
         
            -
             
     | 
| 
       102 
     | 
    
         
            -
             
     | 
| 
      
 128 
     | 
    
         
            +
                def process_attachments
         
     | 
| 
      
 129 
     | 
    
         
            +
                  return if attachment_names.empty?
         
     | 
| 
      
 130 
     | 
    
         
            +
                  attachment_names.map { |n| process_attachment_name n }
         
     | 
| 
      
 131 
     | 
    
         
            +
                end
         
     | 
| 
       103 
132 
     | 
    
         | 
| 
       104 
     | 
    
         
            -
             
     | 
| 
       105 
     | 
    
         
            -
             
     | 
| 
       106 
     | 
    
         
            -
             
     | 
| 
       107 
     | 
    
         
            -
             
     | 
| 
       108 
     | 
    
         
            -
                if a.save
         
     | 
| 
       109 
     | 
    
         
            -
                  send("#{name}=", a)
         
     | 
| 
      
 133 
     | 
    
         
            +
                def remove_attachment(name)
         
     | 
| 
      
 134 
     | 
    
         
            +
                  return unless send(name).destroy
         
     | 
| 
      
 135 
     | 
    
         
            +
                  n = attachment_name_remove(name)
         
     | 
| 
      
 136 
     | 
    
         
            +
                  send("#{name}=", nil)
         
     | 
| 
       110 
137 
     | 
    
         
             
                  send("#{n}=", nil)
         
     | 
| 
       111 
     | 
    
         
            -
                else
         
     | 
| 
       112 
     | 
    
         
            -
                  errors.add(name, a.errors.full_messages.join(','))
         
     | 
| 
       113 
     | 
    
         
            -
                  false
         
     | 
| 
       114 
138 
     | 
    
         
             
                end
         
     | 
| 
       115 
     | 
    
         
            -
              end
         
     | 
| 
       116 
     | 
    
         
            -
             
     | 
| 
       117 
     | 
    
         
            -
              def process_attachment?(name)
         
     | 
| 
       118 
     | 
    
         
            -
                n = attachment_name(name)
         
     | 
| 
       119 
     | 
    
         
            -
                respond_to?(n) && send(n).present?
         
     | 
| 
       120 
     | 
    
         
            -
              end
         
     | 
| 
       121 
     | 
    
         
            -
             
     | 
| 
       122 
     | 
    
         
            -
              def process_attachment_name(name)
         
     | 
| 
       123 
     | 
    
         
            -
                process_attachment(name) if process_attachment?(name)
         
     | 
| 
       124 
     | 
    
         
            -
                remove_attachment(name) if remove_attachment?(name)
         
     | 
| 
       125 
     | 
    
         
            -
              end
         
     | 
| 
       126 
139 
     | 
    
         | 
| 
       127 
     | 
    
         
            -
             
     | 
| 
       128 
     | 
    
         
            -
             
     | 
| 
       129 
     | 
    
         
            -
             
     | 
| 
       130 
     | 
    
         
            -
             
     | 
| 
       131 
     | 
    
         
            -
             
     | 
| 
       132 
     | 
    
         
            -
             
     | 
| 
       133 
     | 
    
         
            -
                 
     | 
| 
       134 
     | 
    
         
            -
                n = attachment_name_remove(name)
         
     | 
| 
       135 
     | 
    
         
            -
                send("#{name}=", nil)
         
     | 
| 
       136 
     | 
    
         
            -
                send("#{n}=", nil)
         
     | 
| 
       137 
     | 
    
         
            -
              end
         
     | 
| 
       138 
     | 
    
         
            -
             
     | 
| 
       139 
     | 
    
         
            -
              def remove_attachment?(name)
         
     | 
| 
       140 
     | 
    
         
            -
                n = attachment_name_remove(name)
         
     | 
| 
       141 
     | 
    
         
            -
                respond_to?(n) &&
         
     | 
| 
       142 
     | 
    
         
            -
                  send(n).present? &&
         
     | 
| 
       143 
     | 
    
         
            -
                  send(n).to_i > 0 &&
         
     | 
| 
       144 
     | 
    
         
            -
                  send(name).present?
         
     | 
| 
       145 
     | 
    
         
            -
              end
         
     | 
| 
      
 140 
     | 
    
         
            +
                def remove_attachment?(name)
         
     | 
| 
      
 141 
     | 
    
         
            +
                  n = attachment_name_remove(name)
         
     | 
| 
      
 142 
     | 
    
         
            +
                  respond_to?(n) &&
         
     | 
| 
      
 143 
     | 
    
         
            +
                    send(n).present? &&
         
     | 
| 
      
 144 
     | 
    
         
            +
                    send(n).to_i > 0 &&
         
     | 
| 
      
 145 
     | 
    
         
            +
                    send(name).present?
         
     | 
| 
      
 146 
     | 
    
         
            +
                end
         
     | 
| 
       146 
147 
     | 
    
         | 
| 
       147 
     | 
    
         
            -
             
     | 
| 
       148 
     | 
    
         
            -
             
     | 
| 
       149 
     | 
    
         
            -
             
     | 
| 
       150 
     | 
    
         
            -
             
     | 
| 
       151 
     | 
    
         
            -
             
     | 
| 
       152 
     | 
    
         
            -
             
     | 
| 
       153 
     | 
    
         
            -
             
     | 
| 
       154 
     | 
    
         
            -
             
     | 
| 
       155 
     | 
    
         
            -
             
     | 
| 
       156 
     | 
    
         
            -
             
     | 
| 
       157 
     | 
    
         
            -
             
     | 
| 
       158 
     | 
    
         
            -
             
     | 
| 
       159 
     | 
    
         
            -
             
     | 
| 
       160 
     | 
    
         
            -
             
     | 
| 
       161 
     | 
    
         
            -
             
     | 
| 
       162 
     | 
    
         
            -
             
     | 
| 
       163 
     | 
    
         
            -
             
     | 
| 
       164 
     | 
    
         
            -
             
     | 
| 
       165 
     | 
    
         
            -
             
     | 
| 
       166 
     | 
    
         
            -
             
     | 
| 
       167 
     | 
    
         
            -
             
     | 
| 
       168 
     | 
    
         
            -
             
     | 
| 
       169 
     | 
    
         
            -
             
     | 
| 
       170 
     | 
    
         
            -
             
     | 
| 
       171 
     | 
    
         
            -
             
     | 
| 
       172 
     | 
    
         
            -
             
     | 
| 
      
 148 
     | 
    
         
            +
                # rubocop:disable all
         
     | 
| 
      
 149 
     | 
    
         
            +
                def process_multiple_attachments
         
     | 
| 
      
 150 
     | 
    
         
            +
                  return if multiple_attachment_names.empty?
         
     | 
| 
      
 151 
     | 
    
         
            +
                  multiple_attachment_names.each do |thing|
         
     | 
| 
      
 152 
     | 
    
         
            +
                    at = "#{thing.to_s.singularize}_attachment".to_sym
         
     | 
| 
      
 153 
     | 
    
         
            +
                    alt = "#{thing.to_s.singularize}_attachment_alt".to_sym
         
     | 
| 
      
 154 
     | 
    
         
            +
                    att = "#{thing.to_s.singularize}_attachment_title".to_sym
         
     | 
| 
      
 155 
     | 
    
         
            +
                    atr = "#{thing.to_s.singularize}_attachment_remove".to_sym
         
     | 
| 
      
 156 
     | 
    
         
            +
                    atu = "#{thing.to_s.singularize}_attachment_url".to_sym
         
     | 
| 
      
 157 
     | 
    
         
            +
                    if respond_to?(thing) && respond_to?(at) && send(at).present?
         
     | 
| 
      
 158 
     | 
    
         
            +
                      a = Asset.new(attachment: send(at), title: send(att), alt: send(alt), assetable_type: self.class.name, assetable_id: id, url: send(atu))
         
     | 
| 
      
 159 
     | 
    
         
            +
                      if a.alt.present? && a.title.blank?
         
     | 
| 
      
 160 
     | 
    
         
            +
                        a.title = a.alt
         
     | 
| 
      
 161 
     | 
    
         
            +
                      elsif a.alt.blank? && a.title.present?
         
     | 
| 
      
 162 
     | 
    
         
            +
                        a.alt = a.title
         
     | 
| 
      
 163 
     | 
    
         
            +
                      end
         
     | 
| 
      
 164 
     | 
    
         
            +
                      if a.save
         
     | 
| 
      
 165 
     | 
    
         
            +
                        send("#{at}=", nil)
         
     | 
| 
      
 166 
     | 
    
         
            +
                        send("#{alt}=", nil)
         
     | 
| 
      
 167 
     | 
    
         
            +
                        send("#{att}=", nil)
         
     | 
| 
      
 168 
     | 
    
         
            +
                        send("#{atr}=", nil)
         
     | 
| 
      
 169 
     | 
    
         
            +
                        send("#{atu}=", nil)
         
     | 
| 
      
 170 
     | 
    
         
            +
                        send("#{thing.to_s.pluralize.to_sym}=", send("#{thing.to_s.pluralize.to_sym}") + [a])
         
     | 
| 
      
 171 
     | 
    
         
            +
                      else
         
     | 
| 
      
 172 
     | 
    
         
            +
                        errors.add(thing, a.errors.full_messages.join(','))
         
     | 
| 
      
 173 
     | 
    
         
            +
                        return false
         
     | 
| 
      
 174 
     | 
    
         
            +
                      end
         
     | 
| 
      
 175 
     | 
    
         
            +
                    elsif respond_to?(atr) && send(atr).present? && send(atr).to_i > 0 && send(thing).present?
         
     | 
| 
      
 176 
     | 
    
         
            +
                      send(thing).destroy_all
         
     | 
| 
       173 
177 
     | 
    
         
             
                    end
         
     | 
| 
       174 
     | 
    
         
            -
                  elsif respond_to?(atr) && send(atr).present? && send(atr).to_i > 0 && send(thing).present?
         
     | 
| 
       175 
     | 
    
         
            -
                    send(thing).destroy_all
         
     | 
| 
       176 
178 
     | 
    
         
             
                  end
         
     | 
| 
       177 
179 
     | 
    
         
             
                end
         
     | 
| 
      
 180 
     | 
    
         
            +
                # rubocop:enable all
         
     | 
| 
       178 
181 
     | 
    
         
             
              end
         
     | 
| 
       179 
     | 
    
         
            -
              # rubocop:enable all
         
     | 
| 
       180 
182 
     | 
    
         
             
            end
         
     | 
| 
         Binary file 
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: morse_assetable
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 1.0.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Terry S
         
     | 
| 
         @@ -72,6 +72,7 @@ files: 
     | 
|
| 
       72 
72 
     | 
    
         
             
            - bin/setup
         
     | 
| 
       73 
73 
     | 
    
         
             
            - lib/morse_assetable.rb
         
     | 
| 
       74 
74 
     | 
    
         
             
            - lib/morse_assetable/version.rb
         
     | 
| 
      
 75 
     | 
    
         
            +
            - morse_assetable-0.2.2.gem
         
     | 
| 
       75 
76 
     | 
    
         
             
            - morse_assetable.gemspec
         
     | 
| 
       76 
77 
     | 
    
         
             
            homepage: https://github.com/morsedigital/morse_assetable.git
         
     | 
| 
       77 
78 
     | 
    
         
             
            licenses:
         
     |