Class: Octonore::Template
- Inherits:
-
Object
- Object
- Octonore::Template
- Defined in:
- lib/octonore/template.rb
Overview
A gitignore template. Templates have two attributes: a name and a source.
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#source ⇒ Object
Returns the value of attribute source.
Class Method Summary collapse
-
.list ⇒ Array
List available templates.
Instance Method Summary collapse
-
#initialize(name) ⇒ String
constructor
Create a new template.
-
#reload ⇒ String
Reload the Gitignore source from Github.
Constructor Details
#initialize(name) ⇒ String
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/octonore/template.rb', line 28 def initialize(name) # Get two arrays of all of the names of templates available. Downcase # one. list = self.class.list down_list = list.map(&:downcase) # Create a hash from the lowercase names to the normal names so we can # make the user-specified name case-insensitive. list_hash = Hash[down_list.zip(list)] # Downcase the the user's name selection and get the matching normal # name in the list_hash self.name = list_hash[name.downcase] # Retrieve the information from Github for their template reload end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/octonore/template.rb', line 7 def name @name end |
#source ⇒ Object
Returns the value of attribute source.
7 8 9 |
# File 'lib/octonore/template.rb', line 7 def source @source end |
Class Method Details
.list ⇒ Array
List available templates
Example:
>> Octonore::Template.list
15 16 17 18 |
# File 'lib/octonore/template.rb', line 15 def self.list raw_list = Octonore::HTTPHelper.instance.get("/templates") parsed_list = raw_list.parsed_response end |
Instance Method Details
#reload ⇒ String
Reload the Gitignore source from Github.
Example:
>> outdated_template.source = nil
=> nil
>> outdated_template.reload
=> "# Object files\n*.o\n\n# Libraries\n*.lib..."
>> outdated_template.source
=> "# Object files\n*.o\n\n# Libraries\n*.lib..."
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/octonore/template.rb', line 55 def reload data = get_template_hash @name if valid_template_hash? data @source = data["source"] else raise GitignoreTemplateNotFoundError, "Template '#{@name}' does not exist!" end end |