class Netfira::WebConnect::RackApp::Action::Version8::Settings
Public Instance Methods
call()
click to toggle source
# File lib/netfira/web_connect/rack_app/actions/version_8/settings.rb, line 4 def call allow :put, :post, :get, :delete key = path && path.first if key handle_single key else handle_multiple end end
Private Instance Methods
delete_all()
click to toggle source
# File lib/netfira/web_connect/rack_app/actions/version_8/settings.rb, line 70 def delete_all shop.setting_models.destroy_all {} end
delete_single(key)
click to toggle source
# File lib/netfira/web_connect/rack_app/actions/version_8/settings.rb, line 44 def delete_single(key) shop.setting_models.where(key: key).destroy_all {} end
get_all()
click to toggle source
# File lib/netfira/web_connect/rack_app/actions/version_8/settings.rb, line 66 def get_all {settings: shop.setting_models.map{ |model| [model.key, [model.value.b].pack('m0')] }.to_h} end
get_single(key)
click to toggle source
# File lib/netfira/web_connect/rack_app/actions/version_8/settings.rb, line 37 def get_single(key) setting = shop.setting_models.find_by(key: key) raise NotFound unless setting header 'Content-Type', setting.content_type setting.value end
handle_multiple()
click to toggle source
# File lib/netfira/web_connect/rack_app/actions/version_8/settings.rb, line 49 def handle_multiple case verb when :put, :post then update_multiple when :get then get_all when :delete then delete_all else raise MethodNotAllowed end end
handle_single(key)
click to toggle source
# File lib/netfira/web_connect/rack_app/actions/version_8/settings.rb, line 16 def handle_single(key) case verb when :put, :post then update_single key when :get then get_single key when :delete then delete_single key else raise MethodNotAllowed end end
update_multiple()
click to toggle source
# File lib/netfira/web_connect/rack_app/actions/version_8/settings.rb, line 58 def update_multiple allow Hash input.each do |key, value| shop.settings[key] = value.unpack('m').first end {} end
update_single(key)
click to toggle source
# File lib/netfira/web_connect/rack_app/actions/version_8/settings.rb, line 25 def update_single(key) if input.respond_to? :read setting = shop.setting_models.find_or_initialize_by(key: key) setting.value = input.read setting.content_type = env['CONTENT_TYPE'] || 'application/x-octet-stream' setting.save else shop.settings[key] = input end {} end