Why the method promote_chat_member can't be used in group, but only in supergroup, is there an alternative to this method in group? - pyrogram

Why the method promote_chat_member can't be used in group, but only in supergroup, is there an alternative to this method in group?
https://docs.pyrogram.org/api/methods/promote_chat_member#pyrogram.Client.promote_chat_member

Related

OGNL needs to call a method

I need to call a method from my action object inside the JSP, something like:
var currentStatus = ${getCurrentStatus()};
I cannot call an attribute, and I tried following this answer (How to call an action method using OGNL) and it didn't work.
There are a variety of ways to call methods (on actions, on other objects, or static methods from classes) from OGNL.
In this case, however, I don't see any issue with using a normal accessor. Note that the JavaBean convention is almost (completely?) about naming. A getter named getCurrentStatus(), accessed simply in OGNL via currentStatus, can contain whatever code you want.
This could include the DB access you mention in your question, etc.

Rails/ActiveRecord .where method naming collision with Ruby Gem class method

I am working on a Ruby gem that will be a REST API wrapper.
What I would like to do is have a class that can be instantiated from the gem with a method similar to Rails/ActiveRecord 'where' method such that I can pass a SQL-like syntax in the method and have some JSON returned. Something like:
include 'my-gem'
test = MyGem::ClassExample.where('name like %test%')
# returns JSON object from REST API
My concern is if I were to include this gem into a Ruby on Rails application, would this 'where' method have a naming collision with ActiveRecord's 'where' or would the 'where' method be the one that I had defined in my class?
Basically, I think it should be okay, but I am scared of having to refactor a bunch of tests and rename a bunch of methods because of Rails magic/my ignorance.
By the way, I am not worried about sanitizing input, the REST API does not provide direct SQL/database access and it is a closed-source product. There is some configuration that needs to be done upfront that I have not included in this example, I just wanted to know if I could use this method name or if there were best practices/potential issues that I may be in conflict with.
Classes are namespaces.
If you define where on your own class and Rails defines where on another class you will not have a conflict. This is the case for both instance methods and class methods, which after all are just instance methods on the singleton class of the class.
However, if you were to define where on Object or another top-level class then you'll run into plenty of conflict because all classes are subclassing these classes.

When should I use named scope and when class methods?

Which one would be preferable to use? Named scope or class methods? The use case is that the user selects a list box in the UI and based on the selected item, the table beneath it gets sorted. This functionality is across the application and is for many models.
The most important thing is that you do what feels right and that you're consistent with it. If something seems like it would be better in a method, use a method.
As of Rails 3, named scopes and class methods can function almost identically. However, the only "rules" I tend to follow when deciding on one or the other:
Use named scopes when an argument is NOT required
Use class methods when an argument is required
I also tend to use named scopes when I plan on chaining them together, as they tend to be short with minimal logic.

Call a method inside the model

I've defined a function called hash_swap inside the User model, but when I call it it always says Method not found. How could I call a function inside the model ?
If you want to call it on the class layer:
Model.hash_swap
you'll have to define the method as class method.
def self.hash_swap
end
If you're calling a function thats been declared inside the model, WITHIN the model then its straight-forward.
hash_swap
will call the function. (Ofcourse I'm assuming you don't have any parameters.)
It would be more helpful if you pasted your User model here.

Symfony: trying to overwriting a method of a symfony class

i want to overwrite a method of
symfony/lib/plugins/sfDoctrinePlugin/lib/form/sfFormDoctrine.class.php.
I think a good way could be writing again the method in the form class
where i need that method.
In that case if i need that method in other form class should i write
again the new method, so i would break the rule DRY...
So is there any better way?
Regards
Javi
You should be using BaseFormDoctrine if this is a Doctrine specific method or BaseForm if you want the method to apply to all forms. These form classes are provided specifically for this purpose.
Piggybacking on Colonel Sponz's answer, I've done this many times by extending the class I want to override. By extending the class, you don't have to duplicate anything. In the method(s) you want to customize, just add your customized code and then call parent::method_name() to execute the same method of the super class. You get all the benefits of both. Calls to methods that don't exist in the subclass will execute against the super class.
It should be noted that this strategy is basic OOP stuff and isn't limited to Symfony or even PHP.
You could create a new class that inherits from sfFormDoctrine that redeclares the methods you need and then use your new class in place of sfFormDoctrine wherever you need that method.

Resources