Class: ActiveAdmin::Dependency::Matcher
- Inherits:
-
Object
- Object
- ActiveAdmin::Dependency::Matcher
- Includes:
- Comparable
- Defined in:
- lib/active_admin/dependency.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(name) ⇒ Matcher
constructor
A new instance of Matcher.
- #inspect ⇒ Object
- #match!(*reqs) ⇒ Object
- #match?(*reqs) ⇒ Boolean
- #spec ⇒ Object
- #spec! ⇒ Object
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
#name ⇒ Object (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 |
#inspect ⇒ Object
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
74 75 76 |
# File 'lib/active_admin/dependency.rb', line 74 def match?(*reqs) !!spec && Gem::Requirement.create(reqs).satisfied_by?(spec.version) end |
#spec ⇒ Object
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 |