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.


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

def initialize(name)
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.


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

def name
  @name
end

Instance Method Details

#<=>(other) ⇒ Object


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

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

#inspectObject


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

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

#match!(*reqs) ⇒ Object


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

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)

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

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

#specObject


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

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

#spec!Object


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

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