lib/active_admin/dependency.rb in activeadmin-1.4.3 vs lib/active_admin/dependency.rb in activeadmin-2.0.0.rc1

- old
+ new

@@ -1,9 +1,9 @@ module ActiveAdmin module Dependency module Requirements - DEVISE = '>= 3.2', '< 5' + DEVISE = '>= 4.0', '< 5' end # Provides a clean interface to check for gem dependencies at runtime. # # ActiveAdmin::Dependency.draper @@ -53,14 +53,10 @@ def self.[](name) Matcher.new name.to_s end - def self.rails5? - rails >= '5.x' - end - class Matcher attr_reader :name def initialize(name) @name = name @@ -91,81 +87,9 @@ end def inspect info = spec ? "#{spec.name} #{spec.version}" : '(missing)' "<ActiveAdmin::Dependency::Matcher for #{info}>" - end - - def adapter - @adapter ||= Adapter.const_get(@name.camelize).new self - end - - def method_missing(method, *args, &block) - if respond_to_missing?(method) - adapter.send method, *args, &block - else - super - end - end - - def respond_to_missing?(method, include_private = false) - adapter.respond_to?(method) || super - rescue NameError - # 🐾 - end - end - - # Dependency adapters provide an easy way to wrap the conditional logic - # necessary to support multiple versions of a gem. - # - # ActiveAdmin::Dependency.rails.adapter.parameterize 'a b' - # => 'a_b' - # - # ActiveAdmin::Dependency.rails.parameterize 'a b' - # => 'a_b' - # - # ActiveAdmin::Dependency.devise.adapter - # -> NameError: uninitialized constant ActiveAdmin::Dependency::Adapter::Devise - # - module Adapter - class Base - def initialize(version) - @version = version - end - end - - class Rails < Base - def optional_belongs_to_flag - if Dependency.rails5? - { optional: true } - else - { required: false } - end - end - - def parameterize(string) - if Dependency.rails5? - string.parameterize separator: '_' - else - string.parameterize '_' - end - end - - def redirect_back(controller, fallback_location) - controller.instance_exec do - if Dependency.rails5? - redirect_back fallback_location: fallback_location - elsif controller.request.headers.key? 'HTTP_REFERER' - redirect_to :back - else - redirect_to fallback_location - end - end - end - - def render_key - Dependency.rails5? ? :body : :text - end end end end end