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)/(.+).liquid\z}
PARTIALS_REGEX =
%r{\A(?-mix:^/?((marketplace_builder|app)/|modules/(.+)(private|public|marketplace_builder|app)/)?)(views/partials|lib)/(.+)\.liquid\z}
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)/(.+).liquid\z}
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{\A(?-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
}
DEFAULT_LANGUAGE =
'en'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(storage) ⇒ App

Returns a new instance of App.



46
47
48
49
50
51
# File 'lib/platformos_check/app.rb', line 46

def initialize(storage)
  @storage = storage
  @grouped_files = {}
  REGEXP_MAP.each_value { |v| @grouped_files[v] ||= {} }
  process_files(storage.files)
end

Instance Attribute Details

#grouped_filesObject (readonly)

Returns the value of attribute grouped_files.



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

def grouped_files
  @grouped_files
end

#storageObject (readonly)

Returns the value of attribute storage.



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

def storage
  @storage
end

Instance Method Details

#[](name_or_relative_path) ⇒ Object



136
137
138
139
140
141
142
143
# File 'lib/platformos_check/app.rb', line 136

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.relative_path.to_s == name_or_relative_path }
  end
end

#allObject



132
133
134
# File 'lib/platformos_check/app.rb', line 132

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

#api_callsObject



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

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

#app_configObject



128
129
130
# File 'lib/platformos_check/app.rb', line 128

def app_config
  grouped_files[ConfigFile]&.values&.first
end

#assetsObject



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

def assets
  grouped_files[AssetFile]&.values
end

#default_languageObject



145
146
147
# File 'lib/platformos_check/app.rb', line 145

def default_language
  DEFAULT_LANGUAGE
end

#emailsObject



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

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

#formsObject



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

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

#graphqlsObject



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

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

#layoutsObject



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

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

#liquidObject



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

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

#notificationsObject



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

def notifications
  emails + smses + api_calls
end

#pagesObject



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

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

#partialsObject



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

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

#process_files(files, remove: false) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/platformos_check/app.rb', line 57

def process_files(files, remove: false)
  files.each do |path|
    regexp, klass = REGEXP_MAP.detect { |k, _v| k.match?(path) }
    next unless regexp

    f = klass.new(path, storage)
    if remove
      @grouped_files[klass].delete(f.name)
    else
      @grouped_files[klass][f.name] = f
    end
  end
  @grouped_files
end

#schemaObject



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

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

#smsesObject



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

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

#translationsObject



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

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

#translations_hashObject



149
150
151
152
153
154
# File 'lib/platformos_check/app.rb', line 149

def translations_hash
  @translations_hash ||= translations.each_with_object({}) do |translation_file, hash|
    hash.deep_merge!(translation_file.content)
    hash
  end
end

#update(files, remove: false) ⇒ Object



53
54
55
# File 'lib/platformos_check/app.rb', line 53

def update(files, remove: false)
  process_files(files, remove:)
end

#yamlObject



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

def yaml
  schema + translations
end