Inheritance with BotPlugin - errbot

I have several helper methods I'd like to include on all of my plugins (things like manipulating lists in persistent storage or setting up config templates), however it looks like from the docs (and in practice) that plugins must inherit from BotPlugin and BotPlugin only. This scuppers my initial idea of having my own base bot class that includes all of these useful behaviors and then having individual plugins inherit from there.
I'm curious why errbot was setup this way and if there might be a reasonable workaround to enable inheritance of plugin classes?
For example:
class BaseBot(BotPlugin):
# common methods
from base_bot import BaseBot
class MyPlugin1(BaseBot):
# doesn't work, errbot won't detect the plugin

however it looks like from the docs (and in practice) that plugins must inherit from BotPlugin and BotPlugin only.
This is correct and the reasons for this mostly have to do with the fact that we use yapsy as our plugin manager. It must know which class from a plugin to actually load (in case a plugin contains multiple classes).
The BotPlugin class also contains all the methods a plugin has at it's disposal (and all the callbacks it may implement) so it also serves as a framework for that.
Now, on to your actual question, you could use a mixin for the shared functionality. Define a common class (lets say, class CommonFunctionalityMixin) which can be imported by all your plugins, then let those plugins inherit from it in addition to BotPlugin:
class MyPlugin(BotPlugin, CommonFunctionalityMixin):
# ...has all of BotPlugin as well as CommonFunctionalityMixin
See errcron for a real-world example of this technique.

Related

How to create custom extension point in ReSharper plugin

We are working on plugin for ReSharper and we want to make our plugin extensible. Seems, we should use ShellComponent attribute to do it but we can not find any examples. Could anybody enplane how to define custom extension point and how to manage extension. Example of code of extension point and extension implementation would be very helpful.
Thanks.
If you're looking to write a plugin that can extend ReSharper, you need to tell ReSharper about the classes in your plugin, by marking them with the [ShellComponent] or [SoutionComponent] attributes. These attributes have different lifetimes - a shell component lasts the lifetime of ReSharper itself, and a solution component is created when a solution is opened and disposed when the solution is closed.
To make ReSharper do something useful with your components, they typically have to implement an interface, such as ICodeCompletionItemsProvider, and sometimes have to use a different attribute, such as [CodeCleanupModule] (which itself derives from ShellComponentAttribute). There are many extension points in ReSharper, and the one that's appropriate for you depends on what you're trying to do - refactoring, unit test provider, code cleanup, code completion items, etc. The devguide provides a good introduction to the more common extension points.
But if you want to make your own plugin extensible, then your component needs to work with a kind of provider pattern, by deferring work to multiple provider instances. For example, code cleanup works by deferring to multiple code cleanup modules, each responsible for cleaning up a different aspect of your code (whitespace, ordering, etc). To do this, your component should take in a collection of providers in the constructor. ReSharper's component model will automatically create a collection of these types and pass them to. More specifically, you should have a constructor that takes an IEnumerable<T> or IViewable<T>, where T is the interface of the provider you're going to define and call. The IEnumerable<T> will give you a simple collection of providers, but IViewable<T> represents an observable collection, and allows you to subscribe to notifications of new providers being made available from the component model.

TypeScript extend object in module

What I want to do is really similar to this and this except I'm trying to figure out how to put an ArrayExtension inside a module.
I'm trying to get something similar to the way C# extension methods work, that way I can just import the module and I'll have my extra methods. The links I provided show how to extend an existing object, but I haven't been able to figure out how to encapsulate that into a module.
If you're targeting non-browser environments like node.js this will be possible because you will be able to pass references to your module's global members, such as Array, to other modules. Those other modules can then extend the passed in object and/or its prototype with extra functionality which will be only accessible by the calling module. Other modules would have to do the same in order to get these extensions; therefore, conflicts are minimized since imports are explicit.
However, in browser environments this is not the case since there is only one window object and any changes to its members are available everywhere. As soon as any of your modules extended Array those extensions would be available to all other modules -- increasing the possibility for conflicts and making the code harder to reason about.
With that said, there are patterns in JS, and therefore TypeScript, which should accomplish what you want. One such pattern is the 'mixin' pattern which allows you to add on extra functionality on an object instance basis. You could separate re-usable code into mixin modules which could then be applied to an object when needed, or even automatically in constructors. Take a look at this for a decent overview and implementation examples: http://javascriptweblog.wordpress.com/2011/05/31/a-fresh-look-at-javascript-mixins/
If you're trying to extend the built in Array type you can't do that within a module. You're extension will need to live in an ArrayEx.ts file and occur outside of any modules. The reason for that is that if you did it within a module you'd be extending the Foo.Array type which isn't the same as Array.
But you said you just want to be able import the module to have your extra methods show up and all you really need to do is add a /// <reference path='ArrayEx.ts' /> to any file you want the extension methods to be available to. This is essentially the same thing.

How add custom method and fields to Liferay User model class

I want to add 3 more methods and one field to liferay.portal.model.User class. Anyone knows how can I do this? Can I switch the class by hook like this:
<service>
<service-type>com.liferay.portal.model.User</service-type>
<service-impl>my.pack.userExpanded</service-impl>
</service>
I want to have a close look at service builder but can't find good sources which will show how to switch liferay class with my own class (cause of too many uses).
So second question is does anyone know about some good tutorial or blogs regarding this? Especially I am interested in adding extra methods and fields.
The standard Liferay Developer Documentation is good:
http://www.liferay.com/documentation/liferay-portal/6.1/development/-/ai/overriding-a-portal-servi-4
Another alternative is to add Custom Fields to User entity:
You can't modify a liferay entity. Neither you can use hook to modify these things, hook can only modify limited things as suggested by the documentation.
I don't think you can even use a EXT to modify a liferay entity.
So now the what comes to my mind remains is to create custom-fields for your field requirement and build a helper utility class which will provide you with your required User methods.
You can make the helper class available to the portal by packaging in a jar and pasting it in the global path (in tomcat [TOMCAT_HOME]/lib/ext).

Symfony 2 - Generate menu entries from available bundles

I'm new to web development with Symphony2 (though definitely not new to web development), and I'm just about to begin a medium sized project, which will be sliced in bundles, as each installation of the app may have a different setup of available functionality.
I would like to generate my navigation dynamically from the available bundles, e.g. if the bundle "foo" is active, a menu entry with a route to the foo main controller action should appear.
Normally, my take on this would be to create a singleton somewhere, which I then would fill during the load() function of a bundle, and during rendering, I would output the singleton.
But symfony2 offers a lot flexibility at this part, so I'm currently evaluating if there may be a better way.
Could services be a way to go here? Or events? Or something with dependency injection, so the bundles get an instance of a NavigationConfigurationElement at construction time?
Any input or thoughts on this, or maybe some links to examples how to do this, would be greatly appreciated.
Best regards,
Jens
i thing the best way to do it, is to use dependency injections tags. you will have to create a dependency injection extension and offer a "tag" that can be used by the various bundles to register their menu entries.
i will not describe you the whole process here because there is plenty of resources about that in the internet.
but to give you a quick outline of what to do
implement a service holding the menu entries (the singleton you where talking about)
process the tag by implementing a compiler pass, this compiler pass will look for all services tagged with the navigation class and register them with the menu service
create a twig function that will use the service to retrieve the menu and render it
write bundles that use the tag and provide menu items
here are some resources that might help you:
http://symfony.com/doc/current/components/dependency_injection/tags.html
http://miguel.ibero.me/es/post/2012-04-28/adding-tags-to-symfony.html
i'm currently implementing a solr bundle for symfony that uses DI tags as well. i have a class called IndexManager that manages various solr indexes from different bundles. i use the DI tag so other bundles can register content/entities they want to be indexed in solr. the principle is the same as with the menu items.
see here: https://github.com/roomthirteen/Room13SolrBundle
the important files are:
adding the compiler pass: https://github.com/roomthirteen/Room13SolrBundle/blob/master/Room13SolrBundle.php
the compiler pass itself: https://github.com/roomthirteen/Room13SolrBundle/blob/master/DependencyInjection/Compiler/SolrCompilerPass.php
hope that helps. any more questins? don't hesitate to ask.

Dynamically create class that mocks another class (like remotingProxy) in haxe

I want to be able to dynamically create a new class that has all of the methods of another class. In particular, I want to make my own kind of remoting proxy.
class ApiProxy extends haxe.remoting.Proxy { }
The new class ApiProxy would have all of the same method names and signatures as Api, and would be compile time checked. Only every invocation is done over the wire, instead of handled locally.
I think that remoting.Proxy is a magic internal class - is this true? Do regular users have the ability to define a class that is as powerfully static as this? I've never seen this done in Java and I'm impressed with it's capabilities in Haxe.
How would I implement my own class like remoting.Proxy?
you can achieve this with macros
take a look at this post to get the idea:
http://haxe.1354130.n2.nabble.com/Macros-Are-Awesome-tc5945711.html
You can write, save to filesystem and register a new Class inside of a Macro, based on type information that was passed to the function.
haxe.remoting.Proxy is indeed "magic", it is described that way in the source comments:
http://code.google.com/p/haxe/source/browse/trunk/std/haxe/remoting/Proxy.hx?r=3592
You can't replicate with "normal" haxe code. Adding/modifying functionality to haxe.remoting.Proxy for your own class will be difficult, but maybe not impossible.
Check the tutorial for the "equivalent" api implementing code:
http://haxe.org/doc/remoting/proxy
However, something like this is probably possible with macros:
http://haxe.org/manual/macros
Working with macros is challenging right now. There is little in the way of documentation or examples, and the macro feature is still under development. However, it lets you have a some control over the compiler during the compilation process, which can be amazingly useful at times.
good luck!

Resources