Class: BooticCli::Themes::ThemeSelector
- Inherits:
-
Object
- Object
- BooticCli::Themes::ThemeSelector
- Defined in:
- lib/bootic_cli/themes/theme_selector.rb
Instance Method Summary collapse
- #find_remote_shop(subdomain = nil) ⇒ Object
-
#initialize(root, prompt:) ⇒ ThemeSelector
constructor
A new instance of ThemeSelector.
- #pair(subdomain, dir) ⇒ Object
- #select_local_theme(dir, subdomain = nil) ⇒ Object
- #select_remote_theme(shop, production = false) ⇒ Object
- #select_theme_pair(subdomain, dir, production = false) ⇒ Object
- #setup_theme_pair(subdomain, dir = nil, wants_public = false, wants_dev = false) ⇒ Object
Constructor Details
#initialize(root, prompt:) ⇒ ThemeSelector
Returns a new instance of ThemeSelector.
7 8 9 10 |
# File 'lib/bootic_cli/themes/theme_selector.rb', line 7 def initialize(root, prompt:) @root = root @prompt = prompt end |
Instance Method Details
#find_remote_shop(subdomain = nil) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/bootic_cli/themes/theme_selector.rb', line 61 def find_remote_shop(subdomain = nil) if !subdomain return root.shops.first end if root.has?(:all_shops) root.all_shops(subdomains: subdomain).find { |s| s.subdomain == subdomain } else root.shops.find { |s| s.subdomain == subdomain } end end |
#pair(subdomain, dir) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/bootic_cli/themes/theme_selector.rb', line 44 def pair(subdomain, dir) shop = find_remote_shop(subdomain) raise "No shop with subdomain #{subdomain}" unless shop theme = select_local_theme(dir, subdomain) theme.write_subdomain theme end |
#select_local_theme(dir, subdomain = nil) ⇒ Object
52 53 54 |
# File 'lib/bootic_cli/themes/theme_selector.rb', line 52 def select_local_theme(dir, subdomain = nil) FSTheme.new(File.(dir), subdomain: subdomain) end |
#select_remote_theme(shop, production = false) ⇒ Object
56 57 58 59 |
# File 'lib/bootic_cli/themes/theme_selector.rb', line 56 def select_remote_theme(shop, production = false) theme = resolve_remote_theme(shop, production) APITheme.new(theme) end |
#select_theme_pair(subdomain, dir, production = false) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/bootic_cli/themes/theme_selector.rb', line 36 def select_theme_pair(subdomain, dir, production = false) local_theme = select_local_theme(dir, subdomain) shop = find_remote_shop(local_theme.subdomain) raise "No shop with subdomain #{local_theme.subdomain}" unless shop remote_theme = select_remote_theme(shop, production) [local_theme, remote_theme] end |
#setup_theme_pair(subdomain, dir = nil, wants_public = false, wants_dev = false) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/bootic_cli/themes/theme_selector.rb', line 12 def setup_theme_pair(subdomain, dir = nil, wants_public = false, wants_dev = false) raise "Cannot pass both public and dev flags at the same time!" if wants_public && wants_dev shop = find_remote_shop(subdomain) raise "No shop with subdomain #{subdomain}" unless shop path = dir || shop.subdomain local_theme = select_local_theme(path, shop.subdomain) remote_theme = select_remote_theme(shop, wants_public) # if no `wants_public` flag was passed and no dev theme is present # ask the user whether he/she wants to create one now. if !wants_public and remote_theme.public? raise 'Dev theme not available!' unless shop.themes.can?(:create_dev_theme) if wants_dev or prompt.yes_or_no?("Would you like to create (and work on) a development version of your theme? (recommended)", true) prompt.say "Good thinking. Creating a development theme out of your current public one...", :green remote_theme = APITheme.new(shop.themes.create_dev_theme) end end [local_theme, remote_theme] end |