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
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(storage) ⇒ App

Returns a new instance of App.



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

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.



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

def grouped_files
  @grouped_files
end

#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



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

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



130
131
132
# File 'lib/platformos_check/app.rb', line 130

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

#api_callsObject



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

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

#app_configObject



126
127
128
# File 'lib/platformos_check/app.rb', line 126

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

#assetsObject



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

def assets
  grouped_files[AssetFile]&.values
end

#emailsObject



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

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

#formsObject



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

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

#graphqlsObject



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

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

#layoutsObject



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

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

#liquidObject



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

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

#notificationsObject



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

def notifications
  emails + smses + api_calls
end

#pagesObject



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

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

#partialsObject



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

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

#process_files(files, remove: false) ⇒ Object



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

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



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

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

#smsesObject



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

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

#translationsObject



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

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

#update(files, remove: false) ⇒ Object



51
52
53
# File 'lib/platformos_check/app.rb', line 51

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

#yamlObject



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

def yaml
  schema + translations
end