Class: Metior::Report::View
- Includes:
- ViewHelper
- Defined in:
- lib/metior/report/view.rb
Overview
This class is an extended Mustache view
A view represents a whole page or a section of a page that displays information about a repository. It is always attached to a specific report and can access the information of the report and the repository.
Direct Known Subclasses
Default::Index, Default::MostSignificantAuthors, Default::MostSignificantCommits, Default::RepositoryInformation, Default::TopCommitters
Class Method Summary collapse
-
.inherited(subclass) ⇒ Object
This will initialize new view classes.
-
.requires(*features) ⇒ Object
Specifies one or more VCS features that are required to generate this view.
Instance Method Summary collapse
-
#initialize(report) ⇒ View
constructor
Initializes this view with the given report.
-
#method_missing(name, *args, &block) ⇒ Object
This will try to render a view as a partial of the current view or call a method of the repository.
-
#render(*args) ⇒ Object
This checks if all required VCS features of this view are available for this report's repository.
-
#repository ⇒ Repository
Returns the repository that is analyzed by the report this view belongs to.
-
#respond_to?(name) ⇒ Boolean
Returns whether the given name refers a partial view that can be rendered or method that can be called.
-
#vcs_name ⇒ Symbol
Returns the name of the VCS the analyzed repository is using.
Methods included from ViewHelper
#count, #even_odd, #reset_count
Constructor Details
#initialize(report) ⇒ View
Initializes this view with the given report
50 51 52 |
# File 'lib/metior/report/view.rb', line 50 def initialize(report) @report = report end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
This will try to render a view as a partial of the current view or call a method of the repository
The partial view will either be aquired from the current view namespace, i.e. the report this view belongs to, or from the default report.
67 68 69 70 71 72 |
# File 'lib/metior/report/view.rb', line 67 def method_missing(name, *args, &block) view_class = Mustache.view_class name return view_class.new(@report).render if view_class != Mustache repository.send name, *args, &block end |
Class Method Details
.inherited(subclass) ⇒ Object
This will initialize new view classes
24 25 26 |
# File 'lib/metior/report/view.rb', line 24 def self.inherited(subclass) subclass.send :class_variable_set, :@@required_features, [] end |
.requires(*features) ⇒ Object
Specifies one or more VCS features that are required to generate this view
41 42 43 44 45 |
# File 'lib/metior/report/view.rb', line 41 def self.requires(*features) required_features = class_variable_get :@@required_features required_features += features class_variable_set :@@required_features, required_features end |
Instance Method Details
#render(*args) ⇒ Object
This checks if all required VCS features of this view are available for this report's repository
81 82 83 84 |
# File 'lib/metior/report/view.rb', line 81 def render(*args) features = self.class.send :class_variable_get, :@@required_features super if features.all? { |feature| repository.supports? feature } end |
#repository ⇒ Repository
Returns the repository that is analyzed by the report this view belongs to
90 91 92 |
# File 'lib/metior/report/view.rb', line 90 def repository @report.repository end |
#respond_to?(name) ⇒ Boolean
Returns whether the given name refers a partial view that can be rendered or method that can be called
This checks whether this view has a method with the given name, or if another view with this name exists, or if the repository has a method with this name.
105 106 107 108 109 |
# File 'lib/metior/report/view.rb', line 105 def respond_to?(name) methods.include?(name.to_s) || Mustache.view_class(name) != Mustache || repository.respond_to?(name) end |
#vcs_name ⇒ Symbol
Returns the name of the VCS the analyzed repository is using
114 115 116 |
# File 'lib/metior/report/view.rb', line 114 def vcs_name repository.vcs::NAME end |