Class: PlatformosCheck::App

Inherits:
Object
  • Object
show all
Defined in:
lib/platformos_check/app.rb

Constant Summary collapse

API_CALLS_REGEX =
%r{\A(?-mix:^/?((marketplace_builder|app)/|modules/(.+)(private|public|marketplace_builder|app)/)?)(notifications/api_call_notifications|api_calls)/(.+)\.liquid\z}
ASSETS_REGEX =
%r{\A(?-mix:^/?((marketplace_builder|app)/|modules/(.+)(private|public|marketplace_builder|app)/)?)assets/}
EMAILS_REGEX =
%r{\A(?-mix:^/?((marketplace_builder|app)/|modules/(.+)(private|public|marketplace_builder|app)/)?)(notifications/email_notifications|emails)/(.+)\.liquid\z}
GRAPHQL_REGEX =
%r{\A(?-mix:^/?((marketplace_builder|app)/|modules/(.+)(private|public|marketplace_builder|app)/)?)(graph_queries|graphql)s?/(.+)\.graphql\z}
MIGRATIONS_REGEX =
%r{\A(?-mix:^/?((marketplace_builder|app)/|modules/(.+)(private|public|marketplace_builder|app)/)?)migrations/(.+)\.liquid\z}
PAGES_REGEX =
%r{\A(?-mix:^/?((marketplace_builder|app)/|modules/(.+)(private|public|marketplace_builder|app)/)?)(pages|views/pages)/(.+)}
PARTIALS_REGEX =
%r{\A(?-mix:^/?((marketplace_builder|app)/|modules/(.+)(private|public|marketplace_builder|app)/)?)(views/partials|lib)/(.+)}
FORMS_REGEX =
%r{\A(?-mix:^/?((marketplace_builder|app)/|modules/(.+)(private|public|marketplace_builder|app)/)?)(form_configurations|forms)/(.+)\.liquid\z}
LAYOUTS_REGEX =
%r{\A(?-mix:^/?((marketplace_builder|app)/|modules/(.+)(private|public|marketplace_builder|app)/)?)(views/layouts)/(.+)}
SCHEMA_REGEX =
%r{\A(?-mix:^/?((marketplace_builder|app)/|modules/(.+)(private|public|marketplace_builder|app)/)?)(custom_model_types|model_schemas|schema)/(.+)\.yml\z}
SMSES_REGEX =
%r{\A(?-mix:^/?((marketplace_builder|app)/|modules/(.+)(private|public|marketplace_builder|app)/)?)(notifications/sms_notifications|smses)/(.+)\.liquid\z}
USER_SCHEMA_REGEX =
%r{\A(?-mix:^/?((marketplace_builder|app)/)?)user.yml}
TRANSLATIONS_REGEX =
%r{\A(?-mix:^/?((marketplace_builder|app)/|modules/(.+)(private|public|marketplace_builder|app)/)?)translations.+.yml}
CONFIG_REGEX =
%r{(?-mix:^\\/?((marketplace_builder|app)\\/)?)config.yml}
REGEXP_MAP =
{
  API_CALLS_REGEX => ApiCallFile,
  ASSETS_REGEX => AssetFile,
  EMAILS_REGEX => EmailFile,
  GRAPHQL_REGEX => GraphqlFile,
  MIGRATIONS_REGEX => MigrationFile,
  PAGES_REGEX => PageFile,
  PARTIALS_REGEX => PartialFile,
  FORMS_REGEX => FormFile,
  LAYOUTS_REGEX => LayoutFile,
  SCHEMA_REGEX => SchemaFile,
  SMSES_REGEX => SmsFile,
  USER_SCHEMA_REGEX => UserSchemaFile,
  TRANSLATIONS_REGEX => TranslationFile,
  CONFIG_REGEX => ConfigFile
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(storage) ⇒ App

Returns a new instance of App.



44
45
46
# File 'lib/platformos_check/app.rb', line 44

def initialize(storage)
  @storage = storage
end

Instance Attribute Details

#storageObject (readonly)

Returns the value of attribute storage.



42
43
44
# File 'lib/platformos_check/app.rb', line 42

def storage
  @storage
end

Instance Method Details

#[](name_or_relative_path) ⇒ Object



127
128
129
130
131
132
133
134
# File 'lib/platformos_check/app.rb', line 127

def [](name_or_relative_path)
  case name_or_relative_path
  when Pathname
    all.find { |t| t.relative_path == name_or_relative_path }
  else
    all.find { |t| t.name == name_or_relative_path }
  end
end

#allObject



123
124
125
# File 'lib/platformos_check/app.rb', line 123

def all
  @all ||= grouped_files.values.map(&:values).flatten
end

#api_callsObject



115
116
117
# File 'lib/platformos_check/app.rb', line 115

def api_calls
  grouped_files[ApiCallFile]&.values || []
end

#assetsObject



67
68
69
# File 'lib/platformos_check/app.rb', line 67

def assets
  grouped_files[AssetFile]&.values
end

#emailsObject



103
104
105
# File 'lib/platformos_check/app.rb', line 103

def emails
  grouped_files[EmailFile]&.values || []
end

#formsObject



91
92
93
# File 'lib/platformos_check/app.rb', line 91

def forms
  grouped_files[FormFile]&.values || []
end

#graphqlsObject



107
108
109
# File 'lib/platformos_check/app.rb', line 107

def graphqls
  grouped_files[GraphqlFile]&.values || []
end

#grouped_filesObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/platformos_check/app.rb', line 48

def grouped_files
  @grouped_files ||= begin
    hash = {}
    REGEXP_MAP.each_value { |v| hash[v] = {} }
    storage.files.each do |path|
      regexp, klass = REGEXP_MAP.detect { |k, _v| k.match?(path) }
      if regexp
        f = klass.new(path, storage)
        hash[klass][f.name] = f
      elsif /\.liquid$/i.match?(path)
        hash[LiquidFile] ||= {}
        f = LiquidFile.new(path, storage)
        hash[LiquidFile][f.name] = f
      end
    end
    hash
  end
end

#layoutsObject



95
96
97
# File 'lib/platformos_check/app.rb', line 95

def layouts
  grouped_files[LayoutFile]&.values || []
end

#liquidObject



71
72
73
# File 'lib/platformos_check/app.rb', line 71

def liquid
  layouts + partials + forms + pages + notifications
end

#notificationsObject



99
100
101
# File 'lib/platformos_check/app.rb', line 99

def notifications
  emails + smses + api_calls
end

#pagesObject



119
120
121
# File 'lib/platformos_check/app.rb', line 119

def pages
  grouped_files[PageFile]&.values || []
end

#partialsObject



87
88
89
# File 'lib/platformos_check/app.rb', line 87

def partials
  grouped_files[PartialFile]&.values || []
end

#schemaObject



79
80
81
# File 'lib/platformos_check/app.rb', line 79

def schema
  grouped_files[SchemaFile]&.values || []
end

#smsesObject



111
112
113
# File 'lib/platformos_check/app.rb', line 111

def smses
  grouped_files[SmsFile]&.values || []
end

#translationsObject



83
84
85
# File 'lib/platformos_check/app.rb', line 83

def translations
  grouped_files[TranslationFile]&.values || []
end

#yamlObject



75
76
77
# File 'lib/platformos_check/app.rb', line 75

def yaml
  schema + translations
end