Class: Bruw::Decidim
- Inherits:
-
Object
- Object
- Bruw::Decidim
- Defined in:
- lib/bruw/decidim.rb
Class Method Summary collapse
-
.curl(settings = {}) ⇒ Object
curl allows to curl a specific file in the target repository Params: settings : Hash owner : String - Repository owner repo : String - Repository name version : String - Specific Decidim version path : String - Target file relative path.
- .curl_response(uri) ⇒ Object
- .current_version ⇒ Object
- .decidim_app? ⇒ Boolean
- .github_repo_base(owner, repo, version) ⇒ Object
- .osp_app? ⇒ Boolean
- .parse_uri(uri) ⇒ Object
- .version ⇒ Object
Class Method Details
.curl(settings = {}) ⇒ Object
curl allows to curl a specific file in the target repository Params: settings : Hash
owner : String - Repository owner
repo : String - Repository name
version : String - Specific Decidim version
path : String - Target file relative path
18 19 20 21 22 23 24 25 |
# File 'lib/bruw/decidim.rb', line 18 def self.curl(settings = {}) base_url = github_repo_base(settings[:owner], settings[:repo], settings[:version]) uri = "#{base_url}/#{settings[:path]}" content = curl_response parse_uri(uri) raise StandardError, "No content for specified path : \n> #{uri}" if content.nil? || content.empty? content end |
.curl_response(uri) ⇒ Object
61 62 63 64 |
# File 'lib/bruw/decidim.rb', line 61 def self.curl_response(uri) response = Net::HTTP.get_response(uri) response&.body if response.is_a?(Net::HTTPOK) && response.respond_to?(:body) end |
.current_version ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/bruw/decidim.rb', line 47 def self.current_version lines = File.open("Gemfile.lock") decidim_version = "" lines.each do |line| next unless /decidim \((?!=).+/i =~ line idx = line.strip.chars.index("(") decidim_version = line.strip[idx + 1..line.strip.size - 2] unless idx.nil? end decidim_version end |
.decidim_app? ⇒ Boolean
31 32 33 |
# File 'lib/bruw/decidim.rb', line 31 def self.decidim_app? !current_version.nil? && !current_version.empty? end |
.github_repo_base(owner, repo, version) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/bruw/decidim.rb', line 39 def self.github_repo_base(owner, repo, version) owner = "decidim" if owner.nil? || owner.empty? repo = "decidim" if repo.nil? || repo.empty? version = "v#{current_version}" if version.nil? || version.empty? "https://raw.githubusercontent.com/#{owner}/#{repo}/#{version}" end |
.osp_app? ⇒ Boolean
35 36 37 |
# File 'lib/bruw/decidim.rb', line 35 def self.osp_app? !Dir.exist?("decidim-core") && !Dir.exist?("decidim-admin") && !Dir.exist?("decidim-initiatives") end |
.parse_uri(uri) ⇒ Object
27 28 29 |
# File 'lib/bruw/decidim.rb', line 27 def self.parse_uri(uri) URI.parse uri end |
.version ⇒ Object
5 6 7 8 9 |
# File 'lib/bruw/decidim.rb', line 5 def self.version raise StandardError, "Not in Decidim project" unless decidim_app? current_version end |