Class: ActiveAdmin::Dependency::Matcher

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/active_admin/dependency.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Matcher

Returns a new instance of Matcher.


65
66
67
# File 'lib/active_admin/dependency.rb', line 65

def initialize(name)
  @name = name
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object


102
103
104
105
106
107
108
# File 'lib/active_admin/dependency.rb', line 102

def method_missing(method, *args, &block)
  if respond_to_missing?(method)
    adapter.send method, *args, &block
  else
    super
  end
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


63
64
65
# File 'lib/active_admin/dependency.rb', line 63

def name
  @name
end

Instance Method Details

#<=>(other) ⇒ Object


89
90
91
# File 'lib/active_admin/dependency.rb', line 89

def <=>(other)
  spec!.version <=> Gem::Version.create(other)
end

#adapterObject


98
99
100
# File 'lib/active_admin/dependency.rb', line 98

def adapter
  @adapter ||= Adapter.const_get(@name.camelize).new self
end

#inspectObject


93
94
95
96
# File 'lib/active_admin/dependency.rb', line 93

def inspect
  info = spec ? "#{spec.name} #{spec.version}" : '(missing)'
  "<ActiveAdmin::Dependency::Matcher for #{info}>"
end

#match!(*reqs) ⇒ Object


81
82
83
84
85
# File 'lib/active_admin/dependency.rb', line 81

def match!(*reqs)
  unless match? reqs
    raise DependencyError, "You provided #{spec!.name} #{spec!.version} but we need: #{reqs.join ', '}."
  end
end

#match?(*reqs) ⇒ Boolean

Returns:

  • (Boolean)

77
78
79
# File 'lib/active_admin/dependency.rb', line 77

def match?(*reqs)
  !!spec && Gem::Requirement.create(reqs).satisfied_by?(spec.version)
end

#respond_to_missing?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)

110
111
112
113
114
# File 'lib/active_admin/dependency.rb', line 110

def respond_to_missing?(method, include_private = false)
  adapter.respond_to?(method) || super
rescue NameError  # 🐾

end

#specObject


69
70
71
# File 'lib/active_admin/dependency.rb', line 69

def spec
  @spec ||= Gem.loaded_specs[name]
end

#spec!Object


73
74
75
# File 'lib/active_admin/dependency.rb', line 73

def spec!
  spec || raise(DependencyError, "To use #{name} you need to specify it in your Gemfile.")
end