Class: SurveillanceAuthority::Sanction
- Inherits:
-
Object
- Object
- SurveillanceAuthority::Sanction
- Includes:
- Singleton
- Defined in:
- lib/surveillance_authority.rb
Constant Summary collapse
- VALID_HOOKS =
[:validation, :validation_on_create, :save, :create]
- @@plugins =
[]
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Class Method Summary collapse
-
.inherited(c) ⇒ Object
register plugins (== SurveillanceAuthority::Sanction Sub-Classes) automatically when they get defined.
Instance Method Summary collapse
- #method_missing(method_name, *args) ⇒ Object
-
#plugins_methods ⇒ Object
build a hash containing all available public plugin methods.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/surveillance_authority.rb', line 34 def method_missing( method_name, *args ) @plugins_methods ||= {} if @plugins_methods[method_name.to_sym] || plugins_methods[method_name.to_sym] plugins_methods[method_name.to_sym].call( *args ) else raise "no method called #{method_name}" end end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
7 8 9 |
# File 'lib/surveillance_authority.rb', line 7 def config @config end |
Class Method Details
.inherited(c) ⇒ Object
register plugins (== SurveillanceAuthority::Sanction Sub-Classes) automatically when they get defined
14 15 16 17 18 19 20 |
# File 'lib/surveillance_authority.rb', line 14 def self.inherited(c) c.class_eval do include Singleton end @@plugins << c end |
Instance Method Details
#plugins_methods ⇒ Object
build a hash containing all available public plugin methods
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/surveillance_authority.rb', line 23 def plugins_methods # caching with @plugins_methods ||= ... does not work here @plugins_methods = @@plugins.inject({}) do |hash, plugin_class| plugin_class.instance_methods(false).each do |method_name| raise "plugin method name clash ... \"#{method_name}\" is defined in \"#{plugin_class.name}\" and \"#{hash[method_name.to_sym].owner.name}\"!" if hash[method_name.to_sym] hash[method_name.to_sym] = plugin_class.instance.method( method_name ) end hash end end |