Module: Nova::Common::StarManagement::ClassMethods
- Included in:
- Star
- Defined in:
- lib/nova/common/star_management.rb
Overview
Class methods.
Instance Attribute Summary collapse
-
#as ⇒ Symbol
The name of the star.
-
#remote ⇒ Module
The remote to use, by default, for stars.
-
#type ⇒ Symbol
The type of the star.
Instance Method Summary collapse
-
#/(other_class) ⇒ Class
Just a way to write it; syntaxic sugar.
-
#[](star_name) ⇒ Hash, Class
An accessor for #stars.
-
#from_target(target) ⇒ nil, Class
Retrieves a star from a given target.
-
#inherited(klass) ⇒ Object
private
When the star is subclassed, add the subclass automatically to the star type list, unless it doesn’t have a proper name.
-
#inspect ⇒ String
Cleans up the inspect a little bit.
-
#method_missing(method, *args, &block) ⇒ Class
Retrieves the star with the given name.
-
#star_type(name) ⇒ self
Adds the Star to the type list.
-
#stars ⇒ Hash{Symbol => Class}
All of the stars that have been defined.
-
#types ⇒ Hash{Symbol => Class}
All of the types of stars.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Class
Retrieves the star with the given name.
104 105 106 107 108 109 110 |
# File 'lib/nova/common/star_management.rb', line 104 def method_missing(method, *args, &block) if (stars.key?(method) || stars[type].key?(method)) && args.length == 0 stars[method] || stars[type][method] else super end end |
Instance Attribute Details
#as ⇒ Symbol
The name of the star.
92 93 94 |
# File 'lib/nova/common/star_management.rb', line 92 def as @as end |
#remote ⇒ Module
The remote to use, by default, for stars.
83 84 85 |
# File 'lib/nova/common/star_management.rb', line 83 def remote @remote ||= Remote::Fake end |
#type ⇒ Symbol
The type of the star.
97 98 99 |
# File 'lib/nova/common/star_management.rb', line 97 def type @type end |
Instance Method Details
#/(other_class) ⇒ Class
Just a way to write it; syntaxic sugar. It returns what was passed.
75 76 77 |
# File 'lib/nova/common/star_management.rb', line 75 def /(other_class) other_class end |
#[](star_name) ⇒ Hash, Class
An accessor for #stars.
56 57 58 |
# File 'lib/nova/common/star_management.rb', line 56 def [](star_name) stars[star_name] end |
#from_target(target) ⇒ nil, Class
Retrieves a star from a given target. The target should be in the format [<type>.]<star name>.
118 119 120 121 122 123 |
# File 'lib/nova/common/star_management.rb', line 118 def from_target(target) type, star_name, action = target.scan(%r{\A(?:([\w]+)\.)?([\w]+)(?:\.([\w]+?))?\z}).first type ||= :star stars[type.intern][star_name.intern] end |
#inherited(klass) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
When the star is subclassed, add the subclass automatically to the star type list, unless it doesn’t have a proper name.
24 25 26 27 28 29 |
# File 'lib/nova/common/star_management.rb', line 24 def inherited(klass) return unless klass.name type = klass.name.gsub(/([A-Z])/) { |a| "_#{a.downcase}" }.gsub("::", "/")[1..-1].intern klass.star_type(type) end |
#inspect ⇒ String
Cleans up the inspect a little bit.
63 64 65 66 |
# File 'lib/nova/common/star_management.rb', line 63 def inspect @_inspect ||= ancestors.take_while { |x| x <= Star }.map(&:name).reverse.join("/").gsub(/\/\z/, "." + as.to_s) end |
#star_type(name) ⇒ self
Adds the Star to the type list.
35 36 37 38 39 40 41 |
# File 'lib/nova/common/star_management.rb', line 35 def star_type(name) types.delete_if { |_, v| v == self } types[name] = self self.type = name stars[name] = {} self end |
#stars ⇒ Hash{Symbol => Class}
All of the stars that have been defined. These are different from star types because they contain information such as events.
48 49 50 |
# File 'lib/nova/common/star_management.rb', line 48 def stars @@stars ||= {} end |
#types ⇒ Hash{Symbol => Class}
All of the types of stars. Should be a key-value pair, with the key being the name, and the value being the class.
15 16 17 |
# File 'lib/nova/common/star_management.rb', line 15 def types @@types ||= {} end |