Class: ConvenientService::Utils::Method::Defined
- Inherits:
-
Support::Command
- Object
- Support::Command
- ConvenientService::Utils::Method::Defined
- Defined in:
- lib/convenient_service/utils/method/defined.rb
Constant Summary collapse
- METHOD_DEFINED_CHECKERS =
{ public: ->(klass, method) { klass.public_method_defined?(method) }, protected: ->(klass, method) { klass.protected_method_defined?(method) }, private: ->(klass, method) { klass.private_method_defined?(method) } }
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#private ⇒ Object
readonly
Returns the value of attribute private.
-
#protected ⇒ Object
readonly
Returns the value of attribute protected.
-
#public ⇒ Object
readonly
Returns the value of attribute public.
Instance Method Summary collapse
- #call ⇒ void
- #initialize(method, klass, public: true, protected: true, private: false) ⇒ void constructor
- #method_defined?(visibility) ⇒ Boolean
- #selected_visibilities ⇒ Array<Symbol>
Methods inherited from Support::Command
Constructor Details
#initialize(method, klass, public: true, protected: true, private: false) ⇒ void
55 56 57 58 59 60 61 |
# File 'lib/convenient_service/utils/method/defined.rb', line 55 def initialize(method, klass, public: true, protected: true, private: false) @method = method.to_s @klass = klass @public = public @protected = protected @private = private end |
Instance Attribute Details
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
23 24 25 |
# File 'lib/convenient_service/utils/method/defined.rb', line 23 def klass @klass end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
17 18 19 |
# File 'lib/convenient_service/utils/method/defined.rb', line 17 def method @method end |
#private ⇒ Object (readonly)
Returns the value of attribute private.
41 42 43 |
# File 'lib/convenient_service/utils/method/defined.rb', line 41 def private @private end |
#protected ⇒ Object (readonly)
Returns the value of attribute protected.
35 36 37 |
# File 'lib/convenient_service/utils/method/defined.rb', line 35 def protected @protected end |
#public ⇒ Object (readonly)
Returns the value of attribute public.
29 30 31 |
# File 'lib/convenient_service/utils/method/defined.rb', line 29 def public @public end |
Instance Method Details
#call ⇒ void
This method returns an undefined value.
66 67 68 69 70 |
# File 'lib/convenient_service/utils/method/defined.rb', line 66 def call return false if selected_visibilities.none? selected_visibilities.any? { |visibility| method_defined?(visibility) } end |
#method_defined?(visibility) ⇒ Boolean
87 88 89 |
# File 'lib/convenient_service/utils/method/defined.rb', line 87 def method_defined?(visibility) METHOD_DEFINED_CHECKERS[visibility].call(klass, method) end |
#selected_visibilities ⇒ Array<Symbol>
79 80 81 |
# File 'lib/convenient_service/utils/method/defined.rb', line 79 def selected_visibilities @selected_visibilities ||= {public: public, protected: protected, private: private}.keep_if { |_, should_be_checked| should_be_checked }.keys end |