Class: Modulorails::Data
- Inherits:
-
Object
- Object
- Modulorails::Data
- Defined in:
- lib/modulorails/data.rb
Overview
Author: Matthieu 'ciappa_m' Ciappara This holds the data gathered by the gem. Some come from the configuration by the gem's user. Some are fetched dynamically.
Constant Summary collapse
- ATTRIBUTE_KEYS =
All the data handled by this class
%i[ name main_developer project_manager repository type rails_name ruby_version rails_version bundler_version modulorails_version adapter db_version adapter_version production_url staging_url review_base_url ].freeze
Instance Method Summary collapse
-
#initialize ⇒ Data
constructor
A new instance of Data.
-
#to_params ⇒ Hash
The payload for the request to the intranet.
-
#to_s ⇒ String
Text version of the data.
Constructor Details
#initialize ⇒ Data
Returns a new instance of Data.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/modulorails/data.rb', line 20 def initialize # Get the gem's configuration to get the application's usual name, main dev and PM configuration = Modulorails.configuration # Get the database connection to identify the database used by the application # or return nil if the database does not exist db_connection = begin ActiveRecord::Base.connection rescue ActiveRecord::NoDatabaseError => e $stderr.puts("[Modulorails] Error: #{e.}") nil end # Get the gem's specifications to fetch the versions of critical gems loaded_specs = Gem.loaded_specs # The data written by the user in the configuration # The name is the usual name of the project, the one used in conversations at Modulotech @name = configuration.name # The main developer, the lead developer, in short the developer to call when something's # wrong with the application ;) @main_developer = configuration.main_developer # The project manager of the application; the other person to call when something's wrong with # the application ;) @project_manager = configuration.project_manager # The URL of the production environment for the application @production_url = configuration.production_url # The URL of the staging environment for the application @staging_url = configuration.staging_url # The base URL of the review environment for the application. # A real review URL is built like this at Modulotech: # https://review-#{shortened_branch_name}-#{ci_slug}.#{review_base_url} # Example: # review_base_url: dev.app.com # branch_name: 786-a_super_branch => shortened_branch_name: 786-a_sup # ci_slug: jzzham # |-> https://review-786-a_sup-jzzham.dev.app.com/ @review_base_url = configuration.review_base_url # Theorically, origin is the main repository of the project and git is the sole VCS we use # at Modulotech @repository = Git.open(::Rails.root).config('remote.origin.url') # The API can handle more project types but this gem is (obviously) intended for Rails # projects only @type = 'rails' # The name defined for the Rails application; it can be completely different from the usual # name or can be the same @rails_name = ::Rails.application.class.name.split('::').first # The Ruby version used by the application @ruby_version = RUBY_VERSION # The Rails version used by the application @rails_version = loaded_specs['rails'].version.version # The bundler version used by the application (especially useful since Bundler 2 and # Bundler 1 are not compatible) @bundler_version = loaded_specs['bundler'].version.version # The version of the gem @modulorails_version = Modulorails::VERSION # The name of the ActiveRecord adapter; it gives the name of the database system too @adapter = db_connection&.adapter_name&.downcase # The version of the database engine; this request works only on MySQL and PostgreSQL # It should not be a problem since those are the sole database engines used at Modulotech @db_version = db_connection&.select_value('SELECT version()') # The version of the ActiveRecord adapter @adapter_version = loaded_specs[@adapter]&.version&.version end |
Instance Method Details
#to_params ⇒ Hash
Returns The payload for the request to the intranet.
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/modulorails/data.rb', line 101 def to_params { 'name' => @name, 'main_developer' => @main_developer, 'project_manager' => @project_manager, 'repository' => @repository, 'app_type' => @type, 'project_data' => { 'name' => @rails_name, 'ruby_version' => @ruby_version, 'rails_version' => @rails_version, 'bundler_version' => @bundler_version, 'modulorails_version' => @modulorails_version, 'database' => { 'adapter' => @adapter, 'db_version' => @db_version, 'gem_version' => @adapter_version }, 'urls' => { 'production' => @production_url, 'staging' => @staging_url, 'review_base' => @review_base_url } } } end |
#to_s ⇒ String
Returns Text version of the data.
95 96 97 |
# File 'lib/modulorails/data.rb', line 95 def to_s ATTRIBUTE_KEYS.map { |key| "#{key}: #{send(key)}" }.join(', ') end |