Class: InterfaceLift::Catalog
- Inherits:
-
Object
- Object
- InterfaceLift::Catalog
- Defined in:
- lib/catalog.rb
Overview
Catalogs manage themes
Instance Attribute Summary collapse
-
#catalog_path ⇒ Object
readonly
Returns the value of attribute catalog_path.
Instance Method Summary collapse
-
#add_theme(theme, repo) ⇒ Object
Download a theme from git repository.
-
#create_catalog_path! ⇒ Object
Create catalog path when it does not exist.
-
#git_repo?(theme) ⇒ Boolean
Is the argumented theme a git repository?.
-
#initialize(catalog_path = nil) ⇒ Catalog
constructor
Construct catalog.
-
#remove_theme(theme) ⇒ Object
Remove theme from catalog.
-
#theme_exists?(theme) ⇒ Boolean
Does the given theme exist in the working path.
-
#themes ⇒ Object
Retrieve themes from specified catalog path.
-
#update_theme(theme) ⇒ Object
Retrieve the latest version of argumented theme from git repository.
Constructor Details
#initialize(catalog_path = nil) ⇒ Catalog
Construct catalog
11 12 13 14 |
# File 'lib/catalog.rb', line 11 def initialize(catalog_path = nil) @catalog_path = catalog_path.nil? ? ::InterfaceLift::DEFAULT_CATALOG_PATH : catalog_path create_catalog_path! end |
Instance Attribute Details
#catalog_path ⇒ Object (readonly)
Returns the value of attribute catalog_path.
8 9 10 |
# File 'lib/catalog.rb', line 8 def catalog_path @catalog_path end |
Instance Method Details
#add_theme(theme, repo) ⇒ Object
Download a theme from git repository
55 56 57 58 |
# File 'lib/catalog.rb', line 55 def add_theme(theme, repo) remove_theme(theme) return ! Git.clone(repo, "#{@catalog_path}/#{theme}").repo.path.nil? end |
#create_catalog_path! ⇒ Object
Create catalog path when it does not exist
61 62 63 |
# File 'lib/catalog.rb', line 61 def create_catalog_path! FileUtils.mkdir_p(@catalog_path) unless File.exists?(@catalog_path) end |
#git_repo?(theme) ⇒ Boolean
Is the argumented theme a git repository?
32 33 34 35 36 37 38 39 40 |
# File 'lib/catalog.rb', line 32 def git_repo?(theme) begin g = Git.open("#{catalog_path}/#{theme}") rescue ArgumentError => e # If the path does not exist it will return an ArgumentError return false end return g.index.readable? end |
#remove_theme(theme) ⇒ Object
Remove theme from catalog
50 51 52 |
# File 'lib/catalog.rb', line 50 def remove_theme(theme) FileUtils.rm_rf("#{@catalog_path}/#{theme}") end |
#theme_exists?(theme) ⇒ Boolean
Does the given theme exist in the working path
27 28 29 |
# File 'lib/catalog.rb', line 27 def theme_exists?(theme) return themes.include?(theme) end |
#themes ⇒ Object
Retrieve themes from specified catalog path
17 18 19 20 21 22 23 24 |
# File 'lib/catalog.rb', line 17 def themes themes = [] Dir.glob("#{@catalog_path}/*").each do |item| theme = item.split("/").last themes << theme if git_repo?(theme) end return themes end |
#update_theme(theme) ⇒ Object
Retrieve the latest version of argumented theme from git repository
43 44 45 46 47 |
# File 'lib/catalog.rb', line 43 def update_theme(theme) return false unless git_repo?(theme) g = Git.open("#{catalog_path}/#{theme}") return ! g.pull.match(/^Updating/).nil? end |