Module: PolyglotCli::Helper::General
- Included in:
- Command::Pull, Command::Push, Command::Setup, Command::Status
- Defined in:
- lib/polyglot_cli/helpers/general.rb
Instance Method Summary collapse
- #config ⇒ Object
- #languages(locale = nil) ⇒ Object
- #project ⇒ Object
- #project_id ⇒ Object
- #remote_translations(language) ⇒ Object
- #select_languages(locale, results) ⇒ Object
- #server_changed? ⇒ Boolean
- #subdomain ⇒ Object
- #token ⇒ Object
- #update_config ⇒ Object
Instance Method Details
#config ⇒ Object
12 13 14 |
# File 'lib/polyglot_cli/helpers/general.rb', line 12 def config @config ||= PolyglotCli::IO::Config.read end |
#languages(locale = nil) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/polyglot_cli/helpers/general.rb', line 30 def languages(locale = nil) prompt.say('Getting languages...') select_languages( locale, PolyglotCli::Resource::Language.with_subdomain(subdomain).token(token).depaginate(project_id: project_id) ) end |
#project ⇒ Object
20 21 22 23 |
# File 'lib/polyglot_cli/helpers/general.rb', line 20 def project prompt.say('Getting project...') PolyglotCli::Resource::Project.with_subdomain(subdomain).token(token).find(project_id).first end |
#project_id ⇒ Object
16 17 18 |
# File 'lib/polyglot_cli/helpers/general.rb', line 16 def project_id config[:project_id] end |
#remote_translations(language) ⇒ Object
56 57 58 59 |
# File 'lib/polyglot_cli/helpers/general.rb', line 56 def remote_translations(language) prompt.say("Getting #{language.name} translations...") PolyglotCli::Resource::Translation.with_subdomain(subdomain).token(token).depaginate(project_id: project_id, language_id: language.id) end |
#select_languages(locale, results) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/polyglot_cli/helpers/general.rb', line 38 def select_languages(locale, results) results.select! { |l| l.locale == locale } if locale.present? if config[:locale_mapping].present? results.select! do |l| l.locale = config[:locale_mapping][l.locale] l.locale.present? end end results end |
#server_changed? ⇒ Boolean
25 26 27 28 |
# File 'lib/polyglot_cli/helpers/general.rb', line 25 def server_changed? return true if config[:project_updated_at].nil? Time.parse(project.updated_at).utc > Time.parse(config[:project_updated_at]).utc end |
#subdomain ⇒ Object
8 9 10 |
# File 'lib/polyglot_cli/helpers/general.rb', line 8 def subdomain config[:subdomain] end |
#token ⇒ Object
4 5 6 |
# File 'lib/polyglot_cli/helpers/general.rb', line 4 def token @token ||= PolyglotCli::IO::Token.read end |
#update_config ⇒ Object
51 52 53 54 |
# File 'lib/polyglot_cli/helpers/general.rb', line 51 def update_config config[:project_updated_at] = project.updated_at PolyglotCli::IO::Config.write(config) end |