flutter_polyglot_cli 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +129 -0
  3. data/Gemfile +3 -0
  4. data/Gemfile.lock +92 -0
  5. data/LICENSE +21 -0
  6. data/README.md +72 -0
  7. data/Rakefile +2 -0
  8. data/bin/console +15 -0
  9. data/bin/setup +8 -0
  10. data/exe/polyflut +52 -0
  11. data/flutter-polyglot-cli.gemspec +34 -0
  12. data/lib/flutter_polyglot_cli/api/base.rb +18 -0
  13. data/lib/flutter_polyglot_cli/api/language.rb +18 -0
  14. data/lib/flutter_polyglot_cli/api/project.rb +7 -0
  15. data/lib/flutter_polyglot_cli/api/session.rb +6 -0
  16. data/lib/flutter_polyglot_cli/api/translation.rb +8 -0
  17. data/lib/flutter_polyglot_cli/api/translation_key.rb +32 -0
  18. data/lib/flutter_polyglot_cli/commands/login.rb +31 -0
  19. data/lib/flutter_polyglot_cli/commands/projects.rb +59 -0
  20. data/lib/flutter_polyglot_cli/commands/pull.rb +89 -0
  21. data/lib/flutter_polyglot_cli/commands/setup.rb +65 -0
  22. data/lib/flutter_polyglot_cli/error_handler.rb +28 -0
  23. data/lib/flutter_polyglot_cli/helpers/depaginate.rb +17 -0
  24. data/lib/flutter_polyglot_cli/helpers/general.rb +122 -0
  25. data/lib/flutter_polyglot_cli/helpers/terminal.rb +15 -0
  26. data/lib/flutter_polyglot_cli/io/config.rb +18 -0
  27. data/lib/flutter_polyglot_cli/io/token.rb +22 -0
  28. data/lib/flutter_polyglot_cli/serializers/localizations/loc_serializer.rb +29 -0
  29. data/lib/flutter_polyglot_cli/serializers/localizations/localization_delegate_serializer.rb +42 -0
  30. data/lib/flutter_polyglot_cli/serializers/localizations/localization_keys_serializer.rb +27 -0
  31. data/lib/flutter_polyglot_cli/serializers/localizations/localization_serializer.rb +47 -0
  32. data/lib/flutter_polyglot_cli/serializers/translations/translations_serializer.rb +25 -0
  33. data/lib/flutter_polyglot_cli/version.rb +3 -0
  34. data/lib/flutter_polyglot_cli.rb +44 -0
  35. metadata +190 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4e0f887cd9f71ec8c78e02f6e91cdea499513dd6832476cb84182331d70a9945
4
+ data.tar.gz: a9638484acba81bb61e4450428a75e51ef96857d149062c35b360b638572dd7f
5
+ SHA512:
6
+ metadata.gz: d6deee52b4e90c401455f672407e3377c9a211afda52cb50527e38a2c1a3511004d9541bb49d3b54de0de3c24abdc48b0fed85c0a2353d51ecf9edacd471c6da
7
+ data.tar.gz: e3013e19e2080dd5e1d6931a3b30b4ade0cff28f9add1e7c07f2f6437b5306e9c9c17d1c7718aaea08b07236f15b83e9e586b9b7361e9d760c72ace4e0f03b65
data/.gitignore ADDED
@@ -0,0 +1,129 @@
1
+
2
+ # Created by https://www.gitignore.io/api/ruby,xcode,macos,visualstudiocode
3
+ # Edit at https://www.gitignore.io/?templates=ruby,xcode,macos,visualstudiocode
4
+
5
+ ### macOS ###
6
+ # General
7
+ .DS_Store
8
+ .AppleDouble
9
+ .LSOverride
10
+
11
+ # Icon must end with two \r
12
+ Icon
13
+
14
+ # Thumbnails
15
+ ._*
16
+
17
+ # Files that might appear in the root of a volume
18
+ .DocumentRevisions-V100
19
+ .fseventsd
20
+ .Spotlight-V100
21
+ .TemporaryItems
22
+ .Trashes
23
+ .VolumeIcon.icns
24
+ .com.apple.timemachine.donotpresent
25
+
26
+ # Directories potentially created on remote AFP share
27
+ .AppleDB
28
+ .AppleDesktop
29
+ Network Trash Folder
30
+ Temporary Items
31
+ .apdisk
32
+
33
+ ### Ruby ###
34
+ *.gem
35
+ *.rbc
36
+ /.config
37
+ /coverage/
38
+ /InstalledFiles
39
+ /pkg/
40
+ /spec/reports/
41
+ /spec/examples.txt
42
+ /test/tmp/
43
+ /test/version_tmp/
44
+ /tmp/
45
+
46
+ # Used by dotenv library to load environment variables.
47
+ # .env
48
+
49
+ # Ignore Byebug command history file.
50
+ .byebug_history
51
+
52
+ ## Specific to RubyMotion:
53
+ .dat*
54
+ .repl_history
55
+ build/
56
+ *.bridgesupport
57
+ build-iPhoneOS/
58
+ build-iPhoneSimulator/
59
+
60
+ ## Specific to RubyMotion (use of CocoaPods):
61
+ #
62
+ # We recommend against adding the Pods directory to your .gitignore. However
63
+ # you should judge for yourself, the pros and cons are mentioned at:
64
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
65
+ # vendor/Pods/
66
+
67
+ ## Documentation cache and generated files:
68
+ /.yardoc/
69
+ /_yardoc/
70
+ /doc/
71
+ /rdoc/
72
+
73
+ ## Environment normalization:
74
+ /.bundle/
75
+ /vendor/bundle
76
+ /lib/bundler/man/
77
+
78
+ # for a library or gem, you might want to ignore these files since the code is
79
+ # intended to run in multiple environments; otherwise, check them in:
80
+ # Gemfile.lock
81
+ # .ruby-version
82
+ # .ruby-gemset
83
+
84
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
85
+ .rvmrc
86
+
87
+ ### VisualStudioCode ###
88
+ .vscode/*
89
+ !.vscode/settings.json
90
+ !.vscode/tasks.json
91
+ !.vscode/launch.json
92
+ !.vscode/extensions.json
93
+
94
+ ### VisualStudioCode Patch ###
95
+ # Ignore all local history of files
96
+ .history
97
+
98
+ ### Xcode ###
99
+ # Xcode
100
+ # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
101
+
102
+ ## User settings
103
+ xcuserdata/
104
+
105
+ ## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
106
+ *.xcscmblueprint
107
+ *.xccheckout
108
+
109
+ ## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
110
+ DerivedData/
111
+ *.moved-aside
112
+ *.pbxuser
113
+ !default.pbxuser
114
+ *.mode1v3
115
+ !default.mode1v3
116
+ *.mode2v3
117
+ !default.mode2v3
118
+ *.perspectivev3
119
+ !default.perspectivev3
120
+
121
+ ### Xcode Patch ###
122
+ *.xcodeproj/*
123
+ !*.xcodeproj/project.pbxproj
124
+ !*.xcodeproj/xcshareddata/
125
+ !*.xcworkspace/contents.xcworkspacedata
126
+ /*.gcno
127
+ **/xcshareddata/WorkspaceSettings.xcsettings
128
+
129
+ # End of https://www.gitignore.io/api/ruby,xcode,macos,visualstudiocode
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,92 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ flutter_polyglot_cli (1.0.0)
5
+ activesupport
6
+ commander
7
+ json_api_client
8
+ osx_keychain
9
+ tty-prompt
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ RubyInline (3.12.5)
15
+ ZenTest (~> 4.3)
16
+ ZenTest (4.12.0)
17
+ activemodel (6.0.0)
18
+ activesupport (= 6.0.0)
19
+ activesupport (6.0.0)
20
+ concurrent-ruby (~> 1.0, >= 1.0.2)
21
+ i18n (>= 0.7, < 2)
22
+ minitest (~> 5.1)
23
+ tzinfo (~> 1.1)
24
+ zeitwerk (~> 2.1, >= 2.1.8)
25
+ addressable (2.7.0)
26
+ public_suffix (>= 2.0.2, < 5.0)
27
+ byebug (11.0.1)
28
+ coderay (1.1.2)
29
+ commander (4.4.7)
30
+ highline (~> 2.0.0)
31
+ concurrent-ruby (1.1.5)
32
+ equatable (0.6.1)
33
+ faraday (0.17.0)
34
+ multipart-post (>= 1.2, < 3)
35
+ faraday_middleware (0.13.1)
36
+ faraday (>= 0.7.4, < 1.0)
37
+ highline (2.0.3)
38
+ i18n (1.7.0)
39
+ concurrent-ruby (~> 1.0)
40
+ json_api_client (1.16.1)
41
+ activemodel (>= 3.2.0)
42
+ activesupport (>= 3.2.0)
43
+ addressable (~> 2.2)
44
+ faraday (~> 0.15, >= 0.15.2)
45
+ faraday_middleware (~> 0.9)
46
+ rack (>= 0.2)
47
+ method_source (0.9.2)
48
+ minitest (5.12.2)
49
+ multipart-post (2.1.1)
50
+ necromancer (0.5.0)
51
+ osx_keychain (1.0.2)
52
+ RubyInline (~> 3)
53
+ pastel (0.7.3)
54
+ equatable (~> 0.6)
55
+ tty-color (~> 0.5)
56
+ pry (0.12.2)
57
+ coderay (~> 1.1.0)
58
+ method_source (~> 0.9.0)
59
+ pry-byebug (3.7.0)
60
+ byebug (~> 11.0)
61
+ pry (~> 0.10)
62
+ public_suffix (4.0.1)
63
+ rack (2.0.7)
64
+ rake (10.5.0)
65
+ thread_safe (0.3.6)
66
+ tty-color (0.5.0)
67
+ tty-cursor (0.7.0)
68
+ tty-prompt (0.19.0)
69
+ necromancer (~> 0.5.0)
70
+ pastel (~> 0.7.0)
71
+ tty-reader (~> 0.6.0)
72
+ tty-reader (0.6.0)
73
+ tty-cursor (~> 0.7)
74
+ tty-screen (~> 0.7)
75
+ wisper (~> 2.0.0)
76
+ tty-screen (0.7.0)
77
+ tzinfo (1.2.5)
78
+ thread_safe (~> 0.1)
79
+ wisper (2.0.1)
80
+ zeitwerk (2.2.0)
81
+
82
+ PLATFORMS
83
+ ruby
84
+
85
+ DEPENDENCIES
86
+ bundler (~> 1.16)
87
+ flutter_polyglot_cli!
88
+ pry-byebug
89
+ rake (~> 10.0)
90
+
91
+ BUNDLED WITH
92
+ 1.17.3
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Filip Gulan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,72 @@
1
+
2
+ # Flutter Polyglot CLI
3
+
4
+ Polyglot client for Flutter development
5
+
6
+ ## Installation
7
+
8
+ To install polyflut simply run:
9
+
10
+ gem install flutter_polyglot_cli
11
+
12
+ If you have any issues with above command, please consult this [thread](https://stackoverflow.com/questions/2119064/sudo-gem-install-or-gem-install-and-gem-locations).
13
+
14
+ You can check if everything is OK running:
15
+
16
+ polyflut --help
17
+
18
+ You should see output with all commands and their description.
19
+
20
+ ## Usage
21
+
22
+ ### Login
23
+
24
+ You will have to login with your Infinum ID if you want to use polyglot:
25
+
26
+ polyflut login
27
+
28
+ If your login action is successful, polyglot will ask you to access Keychain. There it will save your access token, so you don’t have to enter your credentials every time when you use `polyflut` command.
29
+
30
+ ### Setup
31
+
32
+ To setup polyglot in your Xcode project use:
33
+
34
+ polyflut init
35
+
36
+ It will prompt you with project list to select one you are setting up. You can provide source language (Swift/ObjC), translations path and resources path. It will create `polyglot.yml` file which you can edit later and add additional Polyglot projects.
37
+
38
+ Also, you can pass optional parameter `--query` or `-q`. It will prompt you with a list of all projects that match specified query.
39
+
40
+ ### Projects
41
+
42
+ If you want to see all polyglot projects and their `IDs` enter:
43
+
44
+ polyflut projects
45
+
46
+ Also, you can pass optional parameter `--query` or `-q`. It will prompt you with a list of all projects that match specified query.
47
+
48
+ ### Pull
49
+
50
+ Finally, to fetch translations use:
51
+
52
+ $ polyflut pull
53
+
54
+ This will generate a Localization folder in which you will have a Localization class, Localization Delegate, Localization Keys files and an initialize_i18n folder with `.messages` files. This will also create `.arb` files which contain key-value pairs for each language.
55
+
56
+ ### Usage
57
+
58
+ After all the files are generated, all you need to do is add Locales to `supportedLocales` property and add `LocalizationDelegate` to `localizationsDelegates` property of your `MaterialApp`. For iOS, you need to set supported locales in project configuration under the info tab.
59
+
60
+ ## Development
61
+
62
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
63
+
64
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
65
+
66
+ ## Contributing
67
+
68
+ Bug reports and pull requests are welcome on GitHub at https://github.com/infinum/flutter-polyglot-cli.
69
+
70
+ ## License
71
+
72
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler/gem_tasks'
2
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'flutter_polyglot_cli'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ require 'pry'
11
+ Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
15
+
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/polyflut ADDED
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'commander'
5
+ require 'commander/import'
6
+ require 'flutter_polyglot_cli'
7
+
8
+ program :name, 'polyflut'
9
+ program :version, PolyglotFlutter::VERSION
10
+ program :description, 'An Flutter client for managing polyflut\'s translations.'
11
+
12
+ command :login do |c|
13
+ c.syntax = 'polyflut login'
14
+ c.description = 'Fetches and writes your token to the keychain using the email and password you provide.'
15
+ c.action do
16
+ PolyglotFlutter::ErrorHandler.rescuable do
17
+ PolyglotFlutter::Command::Login.init
18
+ end
19
+ end
20
+ end
21
+
22
+ command :init do |c|
23
+ c.syntax = 'polyflut init [options]'
24
+ c.description = 'Sets up a polyflut.yml config for selected project.'
25
+ c.option '--query STRING', String, 'Only show projects which name matches query string.'
26
+ c.action do |_args, options|
27
+ PolyglotFlutter::ErrorHandler.rescuable do
28
+ PolyglotFlutter::Command::Setup.init(options)
29
+ end
30
+ end
31
+ end
32
+
33
+ command :projects do |c|
34
+ c.syntax = 'polyflut projects [options]'
35
+ c.description = 'Lists all available polyflut projects with their IDs.'
36
+ c.option '--query STRING', String, 'Only show projects which name matches query string.'
37
+ c.action do |_args, options|
38
+ PolyglotFlutter::ErrorHandler.rescuable do
39
+ PolyglotFlutter::Command::Projects.init(options)
40
+ end
41
+ end
42
+ end
43
+
44
+ command :pull do |c|
45
+ c.syntax = 'polyflut pull'
46
+ c.description = 'Pulls all translations from Polyglot and generates necessary files'
47
+ c.action do |_args, _options|
48
+ PolyglotFlutter::ErrorHandler.rescuable do
49
+ PolyglotFlutter::Command::Pull.init
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,34 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'flutter_polyglot_cli/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'flutter_polyglot_cli'
7
+ spec.version = PolyglotFlutter::VERSION
8
+ spec.authors = ['Maroje Marcelic']
9
+ spec.email = ['maroje.marcelic@infinum.com']
10
+
11
+ spec.summary = 'A CLI for pulling polyglot translations and generating Flutter Source Files'
12
+ spec.homepage = 'https://github.com/infinum/flutter-polyglot-cli'
13
+ spec.license = 'MIT'
14
+
15
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+
21
+ spec.bindir = 'exe'
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.16'
26
+ spec.add_development_dependency 'pry-byebug'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+
29
+ spec.add_dependency 'activesupport'
30
+ spec.add_dependency 'commander'
31
+ spec.add_dependency 'json_api_client'
32
+ spec.add_dependency 'osx_keychain'
33
+ spec.add_dependency 'tty-prompt'
34
+ end
@@ -0,0 +1,18 @@
1
+ module PolyglotFlutter
2
+ module Resource
3
+ class Base < JsonApiClient::Resource
4
+ extend PolyglotFlutter::Helper::Depaginate
5
+
6
+ self.site = 'https://polyglot.infinum.co/api/v2/'
7
+
8
+ def self.token(token)
9
+ self.connection_options = { headers: { 'X-Auth-Token' => token } }
10
+ self
11
+ end
12
+
13
+ def self.depaginate(opts = {})
14
+ depaginate_query(where(opts))
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module PolyglotFlutter
2
+ module Resource
3
+ class Language < Base
4
+ include Helper::General
5
+
6
+ def code(use_simple_naming = false)
7
+ code = locale.downcase
8
+ return code unless use_simple_naming
9
+
10
+ code.split('_').first
11
+ end
12
+
13
+ def clean_name
14
+ clean_variable_name(name)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,7 @@
1
+ module PolyglotFlutter
2
+ module Resource
3
+ class Project < Base
4
+ has_one :default_language, class_name: :language
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ module PolyglotFlutter
2
+ module Resource
3
+ class Session < Base
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ module PolyglotFlutter
2
+ module Resource
3
+ class Translation < Base
4
+ has_one :translation_key
5
+ has_one :language
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,32 @@
1
+ module PolyglotFlutter
2
+ module Resource
3
+ class TranslationKey < Base
4
+ def clean_translation(language)
5
+ translation_value = name
6
+ translation = translations.find { |key| key.language.id == language.id }
7
+ translation_value = translation.value if translation&.value
8
+ escape_translation(translation_value)
9
+ if translation_value.include? '%'
10
+ translation_value = convert_aruments(translation_value)
11
+ end
12
+ translation_value
13
+ end
14
+
15
+ private
16
+
17
+ def escape_translation(translation)
18
+ translation
19
+ .gsub('"', '\\"')
20
+ end
21
+
22
+ def convert_aruments(translation)
23
+ new_translation = translation
24
+ translation.scan(/(%\w*)/).each_with_index do |match, index|
25
+ new_translation = new_translation.sub(match[0], '{arg' + String(index) + '}')
26
+ end
27
+
28
+ new_translation
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,31 @@
1
+ module PolyglotFlutter
2
+ module Command
3
+ class Login
4
+ include Helper::Terminal
5
+
6
+ def self.init
7
+ new.call
8
+ end
9
+
10
+ def call
11
+ PolyglotFlutter::IO::Token.write(token)
12
+ end
13
+
14
+ private
15
+
16
+ def token
17
+ prompt.say('Logging into API...')
18
+ @data = PolyglotFlutter::Resource::Session.create(email: email, password: password)
19
+ @data.token
20
+ end
21
+
22
+ def email
23
+ prompt.ask('Email:') { |value| value.validate :email }
24
+ end
25
+
26
+ def password
27
+ prompt.mask('Password:')
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,59 @@
1
+ require 'commander/blank'
2
+ require 'commander/command'
3
+
4
+ module PolyglotFlutter
5
+ module Command
6
+ class Projects
7
+ include Helper::Terminal
8
+ include Helper::General
9
+
10
+ attr_accessor :options
11
+
12
+ def self.init(options = Commander::Command::Options.new)
13
+ new(options).call
14
+ end
15
+
16
+ def initialize(options = Commander::Command::Options.new)
17
+ @options = options
18
+ end
19
+
20
+ def call
21
+ list_projects
22
+ end
23
+
24
+ def filtered_projects
25
+ projects
26
+ .select { |key, _id| key[/^(.*?(#{option_query})[^$]*)$/i] }
27
+ .sort_by { |p| p[0].downcase }
28
+ .to_h
29
+ end
30
+
31
+ def projects
32
+ prompt.say('Getting projects...')
33
+ PolyglotFlutter::Resource::Project.token(token).depaginate.each_with_object({}) do |r, hash|
34
+ hash[r.name] = r.id
35
+ end
36
+ end
37
+
38
+ def option_query
39
+ @option_query ||= @options.__hash__.fetch(:query, '')
40
+ end
41
+
42
+ private
43
+
44
+ def list_projects
45
+ projects = filtered_projects
46
+ selection = projects
47
+ .each_with_object({}) do |project, hash|
48
+ project_name = project[0]
49
+ project_id = project[1]
50
+ display_name = "#{project_name} => #{project_id}"
51
+ hash[display_name] = project_id
52
+ end
53
+ prompt.say(" Name - ID: \n ----------")
54
+ selected_id = prompt
55
+ .select('', selection)
56
+ end
57
+ end
58
+ end
59
+ end