Class: Multilocale::Project
- Inherits:
-
Object
- Object
- Multilocale::Project
- Defined in:
- lib/multilocale/project.rb
Overview
A project: the unit an API key is scoped to, and the thing that owns the locale list every download is written from.
The wire format is the API's camelCase document; the readers are the Ruby
names. #to_h always returns the untouched document, so a round-trip
through this class never drops a field the API added yesterday.
Constant Summary collapse
- ATTRIBUTE_NAMES =
{ id: "_id", name: "name", default_locale: "defaultLocale", locales: "locales", context: "context", paths: "paths" }.freeze
Instance Attribute Summary collapse
-
#to_h ⇒ Object
readonly
Returns the value of attribute to_h.
Class Method Summary collapse
-
.to_api(attributes) ⇒ Object
Snake_case keyword arguments -> the camelCase document the API stores.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #[](key) ⇒ Object
-
#context ⇒ Object
Free-text translation context, prepended to every machine translation.
- #creation_time ⇒ Object
- #default_locale ⇒ Object
- #hash ⇒ Object
- #id ⇒ Object
-
#initialize(attributes) ⇒ Project
constructor
A new instance of Project.
- #inspect ⇒ Object
- #last_edit_time ⇒ Object
-
#locales ⇒ Object
The complete locale list.
- #name ⇒ Object
- #organization_id ⇒ Object
-
#paths ⇒ Object
Server-side download paths.
Constructor Details
Instance Attribute Details
#to_h ⇒ Object (readonly)
Returns the value of attribute to_h.
11 12 13 |
# File 'lib/multilocale/project.rb', line 11 def to_h @to_h end |
Class Method Details
.to_api(attributes) ⇒ Object
Snake_case keyword arguments -> the camelCase document the API stores. String keys are passed through untouched so anything not modelled here can still be sent.
87 88 89 90 91 92 93 |
# File 'lib/multilocale/project.rb', line 87 def self.to_api(attributes) return attributes.to_h if attributes.is_a?(Project) attributes.each_with_object({}) do |(key, value), document| document[ATTRIBUTE_NAMES[key] || key.to_s] = value end end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
62 63 64 |
# File 'lib/multilocale/project.rb', line 62 def ==(other) other.is_a?(Project) && other.to_h == to_h end |
#[](key) ⇒ Object
58 59 60 |
# File 'lib/multilocale/project.rb', line 58 def [](key) @to_h[key.to_s] end |
#context ⇒ Object
Free-text translation context, prepended to every machine translation.
40 41 42 |
# File 'lib/multilocale/project.rb', line 40 def context @to_h["context"] end |
#creation_time ⇒ Object
50 51 52 |
# File 'lib/multilocale/project.rb', line 50 def creation_time @to_h["creationTime"] end |
#default_locale ⇒ Object
29 30 31 |
# File 'lib/multilocale/project.rb', line 29 def default_locale @to_h["defaultLocale"] end |
#hash ⇒ Object
67 68 69 |
# File 'lib/multilocale/project.rb', line 67 def hash to_h.hash end |
#id ⇒ Object
17 18 19 |
# File 'lib/multilocale/project.rb', line 17 def id @to_h["_id"] end |
#inspect ⇒ Object
71 72 73 |
# File 'lib/multilocale/project.rb', line 71 def inspect "#<Multilocale::Project id=#{id.inspect} name=#{name.inspect} locales=#{locales.size}>" end |
#last_edit_time ⇒ Object
54 55 56 |
# File 'lib/multilocale/project.rb', line 54 def last_edit_time @to_h["lastEditTime"] end |
#locales ⇒ Object
The complete locale list. Updating it REPLACES it: a project update that omits a locale removes it, it does not merge.
35 36 37 |
# File 'lib/multilocale/project.rb', line 35 def locales @to_h["locales"] || [] end |
#name ⇒ Object
21 22 23 |
# File 'lib/multilocale/project.rb', line 21 def name @to_h["name"] end |
#organization_id ⇒ Object
25 26 27 |
# File 'lib/multilocale/project.rb', line 25 def organization_id @to_h["organizationId"] end |
#paths ⇒ Object
Server-side download paths. The npm CLI resolves project.paths || config.paths, so a value set here wins over the local multilocale.json.
46 47 48 |
# File 'lib/multilocale/project.rb', line 46 def paths @to_h["paths"] end |