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
60 61 62 63 64 65 66 |
# File 'lib/convenient_service/utils/method/defined.rb', line 60 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.
28 29 30 |
# File 'lib/convenient_service/utils/method/defined.rb', line 28 def klass @klass end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
22 23 24 |
# File 'lib/convenient_service/utils/method/defined.rb', line 22 def method @method end |
#private ⇒ Object (readonly)
Returns the value of attribute private.
46 47 48 |
# File 'lib/convenient_service/utils/method/defined.rb', line 46 def private @private end |
#protected ⇒ Object (readonly)
Returns the value of attribute protected.
40 41 42 |
# File 'lib/convenient_service/utils/method/defined.rb', line 40 def protected @protected end |
#public ⇒ Object (readonly)
Returns the value of attribute public.
34 35 36 |
# File 'lib/convenient_service/utils/method/defined.rb', line 34 def public @public end |
Instance Method Details
#call ⇒ void
This method returns an undefined value.
71 72 73 74 75 |
# File 'lib/convenient_service/utils/method/defined.rb', line 71 def call return false if selected_visibilities.none? selected_visibilities.any? { |visibility| method_defined?(visibility) } end |
#method_defined?(visibility) ⇒ Boolean
92 93 94 |
# File 'lib/convenient_service/utils/method/defined.rb', line 92 def method_defined?(visibility) METHOD_DEFINED_CHECKERS[visibility].call(klass, method) end |
#selected_visibilities ⇒ Array<Symbol>
84 85 86 |
# File 'lib/convenient_service/utils/method/defined.rb', line 84 def selected_visibilities @selected_visibilities ||= {public: public, protected: protected, private: private}.keep_if { |_, should_be_checked| should_be_checked }.keys end |