ModuleName and ModuleDependency attributes - name of the module class or name of the module assembly, or fullname of module - prism

Is the string parameter used in a ModuleName and ModuleDependency attributes the name of the module class ,the name of the module assembly, or full name of the module class.
If there are two module projects one named Module1Project and the other named Module2Project.
In Module1Project the name of the module class is Module
1 public class Module1 :IModule
In Module2Project the name of the module class is Module2
public class Module2 :IModule
So what would be the string parameter  used in the ModuleNameAttribute for the both module classes be?
If Module1 had to be loaded before Module2,in the Module2 class what would be the string parameter bein the ModuleDependencyAttribute place above the Module2 class?
All the demo examples I fould the Project and the module class in the project had the same name.

Is the string parameter used in a ModuleName and ModuleDependency attributes the name of the module class, the name of the module assembly, or full name of the module class.
It is the module's name, which defaults to the name of the module class if no ModuleAttribute is present that overrides it.
So what would be the string parameter used in the ModuleNameAttribute for the both module classes be?
You can name the modules whatever you like, but you don't need a ModuleAttribute at all if you like the name of the class (Module1 and Module2 in your example) as name of the module.
The names of project, assembly and namespace don't matter. So, if, for example, you have MyProject.Module1 and TheOtherProject.Module1 as module classes and want to load them both at the same time, it makes sense to distinguish them using ModuleAttribute.ModuleName, if you cannot simply change the names of the classes.
Rant: Module1 isn't a good name for a module. A module, as a class should have a purpose, and a name that reflects it. You don't call your services or tables Service1, Service2, Table3 and Table4, do yo? WCFConnectorModule may be a good name for a module that provides the implementation for some backend-interface. If you can't come up with better names than Module1 and Module2 you most likely don't need or want modules in the first place. You want modules, if you have parts of your application that you want to swap out (without breaking anything) after compiling and probably after deploying. If you don't have this requirement, assemblies or just namespaces are perfectly fine to organize your code.

Related

Set option of autodoc directive for members of another autodoc directive

Problem
To fully use the autodoc potential, I want to document my code with something like:
.. automodule :: mymodule
However, mymodule is made of a class that has it's own documenter. One of my project's dependencies created a subclass of sphinx.ext.autodoc.ClassDocumenter that documents a class it provides. My mymodule is made up of classes derived from that base one. The custom documenter has an option I want to use, how do I provide it while using automodule?
Alternative formulation
Another case that I think is the same problem:
.. automodule :: mymodule
.. automodule :: myothermodule
These two modules are made of classes that will be documented with autoclass. I want to activate the ":inherited-members:" option for classes of the first mymodule but not on the ones of myothermodule. Is this possible?

difference between modules inside a class and class inside a modules in ruby

I think both are used for namespace.
Modules are generally mixed into classes, right? So, what would be the purpose of defining a module inside a class?
Generally speaking modules have two uses:
Namespacing modules. When you nest stuff here and the module is intended only for specifying paths.
Functional modules. When the module has actual functionality that is intended to be called directly on the module or the module is intended to be included/extended.
Classes should be used for functionality only, even though Ruby doesn't enforce it.
Trying to do something but the above (like use module for both namespacing and functionality (1) or use a class for namespacing (2)) will generally confuse you.
(1) Some will disagree pointing to the rails' module with instance methods that also holds another module, called ClassMethods. I think it would have been cleaner if there was a module with two modules - ClassMethods and InstanceMethods instead.
(2) Some will disagree. A probably valid case is if you try to emulate private classes from other languages (where the private class will be nested inside your public class).

Add Ruby classes to a module when defined in separate files

I would like to namespace my Ruby classes by putting them in a module. Indeed, this is a good idea if I decide to publish my Ruby gem so that the class names do not clash with existing classes in another gem. I know I can do the following for a class A::B:
module A
class B
end
end
However, the above is quite cumbersome in that I need to put all my class definitions into a single Ruby source file in order to scope them under the module. I would rather keep my class definitions in separate source files, much like a Java project, so how can I add classes to a module when they are all defined in separate files?
The accepted practice in this case is to wrap every file in module block
# a/b.rb
module A
class B
end
end
# a/c.rb
module A
class C
end
end
Btw. because of the way constant are resolved, it is advisable to use the long form I quoted above instead class A::B
(http://blog.honeybadger.io/avoid-these-traps-when-nesting-ruby-modules/).

How to add classes in different files into one module in Ruby?

I currently creating a gem, so, I have a folder with different files, which contains different classes, this folder will be updated with more files and also current ones will be updated as well, in another file I have a module that should contain these classes.
Currently, I add manually to the module all the classes:
File1.rb:
module MyModule
class ClassA
# code here
end
end
File2.rb:
module MyModule
class ClassB
# code here
end
end
But, since I will add more classes and current classes will be updated this is not optimal and very dangerous to maintain clean, so is there any other way to add classes in different files in one module set in another file?
Thanks in advance
No there is no another way and I don't see any danger in doing it the way you did (correct way).

Extend model with a module inside a folder

All of my modules which extend my models live inside the "app/lib" directory but it's getting cluttered so I want to start grouping them in subfolders. How do I add a folder to the path when extending a module?
My current user model:
class User
extend Match
extend UserAnalytics
extend Gaming
...
I'd like to group these modules in a subfolder "app/lib/user" instead, but how would I specify the new path to the modules?
require "app/lib/user/Match"
...
class Anything
extend Match
Should do the trick.

Resources