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.
61 62 63 |
# File 'lib/active_admin/dependency.rb', line 61 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
59 60 61 |
# File 'lib/active_admin/dependency.rb', line 59 def name @name end |
Instance Method Details
#<=>(other) ⇒ Object
85 86 87 |
# File 'lib/active_admin/dependency.rb', line 85 def <=>(other) spec!.version <=> Gem::Version.create(other) end |
#inspect ⇒ Object
89 90 91 92 |
# File 'lib/active_admin/dependency.rb', line 89 def inspect info = spec ? "#{spec.name} #{spec.version}" : '(missing)' "<ActiveAdmin::Dependency::Matcher for #{info}>" end |
#match!(*reqs) ⇒ Object
77 78 79 80 81 |
# File 'lib/active_admin/dependency.rb', line 77 def match!(*reqs) unless match? reqs raise DependencyError, "You provided #{spec!.name} #{spec!.version} but we need: #{reqs.join ', '}." end end |
#match?(*reqs) ⇒ Boolean
73 74 75 |
# File 'lib/active_admin/dependency.rb', line 73 def match?(*reqs) !!spec && Gem::Requirement.create(reqs).satisfied_by?(spec.version) end |
#spec ⇒ Object
65 66 67 |
# File 'lib/active_admin/dependency.rb', line 65 def spec @spec ||= Gem.loaded_specs[name] end |
#spec! ⇒ Object
69 70 71 |
# File 'lib/active_admin/dependency.rb', line 69 def spec! spec || raise(DependencyError, "To use #{name} you need to specify it in your Gemfile.") end |