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.



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

def initialize(name)
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



60
61
62
# File 'lib/active_admin/dependency.rb', line 60

def name
  @name
end

Instance Method Details

#<=>(other) ⇒ Object



86
87
88
# File 'lib/active_admin/dependency.rb', line 86

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

#inspectObject



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

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

#match!(*reqs) ⇒ Object



78
79
80
81
82
# File 'lib/active_admin/dependency.rb', line 78

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)


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

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

#specObject



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

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

#spec!Object



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

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