mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Rewrite alias_method_chain to use super. Ahhhhh :)
This commit is contained in:
@@ -3,7 +3,7 @@ require 'open_food_network/paperclippable'
|
||||
class ContentConfiguration < Spree::Preferences::FileConfiguration
|
||||
# Header
|
||||
include OpenFoodNetwork::Paperclippable
|
||||
file_preference :logo
|
||||
preference :logo, :file
|
||||
has_attached_file :logo
|
||||
|
||||
# Home page
|
||||
|
||||
@@ -1,36 +1,36 @@
|
||||
module Spree::Preferences
|
||||
class FileConfiguration < Configuration
|
||||
|
||||
# Ideally, we'd alias_method_chain preference to add new type. However, failcake.
|
||||
def self.file_preference(name)
|
||||
preference "#{name}_file_name", :string
|
||||
preference "#{name}_content_type", :string
|
||||
preference "#{name}_file_size", :integer
|
||||
preference "#{name}_updated_at", :string
|
||||
end
|
||||
def self.preference(name, type, *args)
|
||||
if type == :file
|
||||
super "#{name}_file_name", :string, *args
|
||||
super "#{name}_content_type", :string, *args
|
||||
super "#{name}_file_size", :integer, *args
|
||||
super "#{name}_updated_at", :string, *args
|
||||
|
||||
|
||||
# TODO: Rewrite with super
|
||||
|
||||
def get_preference_with_files(key)
|
||||
if !has_preference?(key) && has_attachment?(key)
|
||||
send(key)
|
||||
else
|
||||
get_preference_without_files(key)
|
||||
super name, type, *args
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def get_preference(key)
|
||||
if !has_preference?(key) && has_attachment?(key)
|
||||
send key
|
||||
else
|
||||
super key
|
||||
end
|
||||
end
|
||||
alias_method_chain :get_preference, :files
|
||||
alias :[] :get_preference
|
||||
|
||||
|
||||
def preference_type_with_files(name)
|
||||
def preference_type(name)
|
||||
if has_attachment? name
|
||||
:file
|
||||
else
|
||||
preference_type_without_files(name)
|
||||
super name
|
||||
end
|
||||
end
|
||||
alias_method_chain :preference_type, :files
|
||||
|
||||
|
||||
# Spree's Configuration responds to preference methods via method_missing, but doesn't
|
||||
|
||||
@@ -6,7 +6,7 @@ module Spree
|
||||
preference :name, :string
|
||||
|
||||
include OpenFoodNetwork::Paperclippable
|
||||
file_preference :logo
|
||||
preference :logo, :file
|
||||
has_attached_file :logo
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user