Class: NeetoTranslateCli::NextI18next::PayloadBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/neeto_translate_cli/next_i18next/payload_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ PayloadBuilder

Returns a new instance of PayloadBuilder.



11
12
13
14
15
# File 'lib/neeto_translate_cli/next_i18next/payload_builder.rb', line 11

def initialize(options)
  @options = options
  commit_id = git_commit_id
  @updated_keys = commit_id.empty? ? [] : find_updated_keys(commit_id)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/neeto_translate_cli/next_i18next/payload_builder.rb', line 9

def options
  @options
end

#updated_keysObject (readonly)

Returns the value of attribute updated_keys.



9
10
11
# File 'lib/neeto_translate_cli/next_i18next/payload_builder.rb', line 9

def updated_keys
  @updated_keys
end

Instance Method Details

#no_new_changes?(payload) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/neeto_translate_cli/next_i18next/payload_builder.rb', line 32

def no_new_changes?(payload)
  payload[:frontend][:missing_keys].values.all?(&:empty?)
end

#process!Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/neeto_translate_cli/next_i18next/payload_builder.rb', line 17

def process!
  {
    frontend: {
      en: flatten_hash_with_prefix(frontend_translations[:en]),
      missing_keys: find_missing_keys
    },
    metadata: {
      repo: options[:repo],
      frontend: options[:frontend],
      strategy: options[:strategy],
      branch: options[:branch]
    }
  }
end