Class: ShopifyCLI::Shopifolk

Inherits:
Object
  • Object
show all
Defined in:
lib/shopify_cli/shopifolk.rb

Overview

ShopifyCLI::Shopifolk contains the logic to determine if the user appears to be a Shopify staff

The Shopifolk Feature flag will persist between runs so if the flag is enabled or disabled, it will still be in that same state until the next class invocation.

Constant Summary collapse

GCLOUD_CONFIG_FILE =
File.expand_path("~/.config/gcloud/configurations/config_default")
DEV_PATH =
"/opt/dev"
SECTION =
"core"
FEATURE_NAME =
"shopifolk"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.act_as_shopify_organizationObject



29
30
31
# File 'lib/shopify_cli/shopifolk.rb', line 29

def act_as_shopify_organization
  DB.set(acting_as_shopify_organization: true)
end

.acting_as_shopify_organization?Boolean

Returns:

  • (Boolean)


33
34
35
36
# File 'lib/shopify_cli/shopifolk.rb', line 33

def acting_as_shopify_organization?
  !!(DB.get(:acting_as_shopify_organization) ||
  (Project.has_current? && Project.current.config["shopify_organization"]))
end

.checkObject

will return if the user appears to be a Shopify employee, based on several heuristics

#### Returns

  • ‘is_shopifolk` - returns true if the user is a Shopify Employee

#### Example

ShopifyCLI::Shopifolk.check


25
26
27
# File 'lib/shopify_cli/shopifolk.rb', line 25

def check
  ShopifyCLI::Shopifolk.new.shopifolk?
end

.resetObject



38
39
40
# File 'lib/shopify_cli/shopifolk.rb', line 38

def reset
  DB.del(:acting_as_shopify_organization)
end

Instance Method Details

#shopifolk?Boolean

will return if the user is a Shopify employee

#### Returns

  • ‘is_shopifolk` - returns true if the user has `dev` installed and

a valid google cloud config file with email ending in “@shopify.com”

Returns:

  • (Boolean)


51
52
53
54
55
56
57
58
59
60
61
# File 'lib/shopify_cli/shopifolk.rb', line 51

def shopifolk?
  return true if Feature.enabled?(FEATURE_NAME)

  if shopifolk_by_gcloud? && shopifolk_by_dev?
    ShopifyCLI::Feature.enable(FEATURE_NAME)
    true
  else
    ShopifyCLI::Feature.disable(FEATURE_NAME)
    false
  end
end