Class: PlanMyStuff::BaseMetadata
- Inherits:
-
Object
- Object
- PlanMyStuff::BaseMetadata
- Defined in:
- lib/plan_my_stuff/base_metadata.rb
Direct Known Subclasses
BaseProjectMetadata, CommentMetadata, IssueMetadata, ProjectItemMetadata
Constant Summary collapse
- SCHEMA_VERSION =
'1'
Instance Attribute Summary collapse
-
#app_name ⇒ String?
Consuming app name from config.
-
#created_by ⇒ Integer?
Consuming app’s user ID of the creator.
-
#custom_fields ⇒ PlanMyStuff::CustomFields?
App-defined custom field values.
-
#gem_version ⇒ String
Gem version that created this metadata.
-
#rails_env ⇒ String?
Rails environment.
-
#schema_version ⇒ String
Schema version for forward compatibility (starts at “1”).
-
#visibility ⇒ String
“public” or “internal”.
Instance Method Summary collapse
-
#initialize ⇒ BaseMetadata
constructor
A new instance of BaseMetadata.
- #internal? ⇒ Boolean
- #public? ⇒ Boolean
- #to_h ⇒ Hash
- #to_json ⇒ String
-
#validate_custom_fields! ⇒ true
Validates custom fields against the schema.
Constructor Details
#initialize ⇒ BaseMetadata
Returns a new instance of BaseMetadata.
92 93 94 95 |
# File 'lib/plan_my_stuff/base_metadata.rb', line 92 def initialize @visibility = 'internal' @custom_fields = {} end |
Instance Attribute Details
#app_name ⇒ String?
Returns consuming app name from config.
17 18 19 |
# File 'lib/plan_my_stuff/base_metadata.rb', line 17 def app_name @app_name end |
#created_by ⇒ Integer?
Returns consuming app’s user ID of the creator.
19 20 21 |
# File 'lib/plan_my_stuff/base_metadata.rb', line 19 def created_by @created_by end |
#custom_fields ⇒ PlanMyStuff::CustomFields?
Returns app-defined custom field values.
23 24 25 |
# File 'lib/plan_my_stuff/base_metadata.rb', line 23 def custom_fields @custom_fields end |
#gem_version ⇒ String
Returns gem version that created this metadata.
13 14 15 |
# File 'lib/plan_my_stuff/base_metadata.rb', line 13 def gem_version @gem_version end |
#rails_env ⇒ String?
Returns Rails environment.
15 16 17 |
# File 'lib/plan_my_stuff/base_metadata.rb', line 15 def rails_env @rails_env end |
#schema_version ⇒ String
Returns schema version for forward compatibility (starts at “1”).
11 12 13 |
# File 'lib/plan_my_stuff/base_metadata.rb', line 11 def schema_version @schema_version end |
#visibility ⇒ String
Returns “public” or “internal”.
21 22 23 |
# File 'lib/plan_my_stuff/base_metadata.rb', line 21 def visibility @visibility end |
Instance Method Details
#internal? ⇒ Boolean
111 112 113 |
# File 'lib/plan_my_stuff/base_metadata.rb', line 111 def internal? visibility == 'internal' end |
#public? ⇒ Boolean
116 117 118 |
# File 'lib/plan_my_stuff/base_metadata.rb', line 116 def public? visibility == 'public' end |
#to_h ⇒ Hash
98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/plan_my_stuff/base_metadata.rb', line 98 def to_h { schema_version: schema_version, gem_version: gem_version, rails_env: rails_env, app_name: app_name, created_by: created_by, visibility: visibility, custom_fields: custom_fields.to_h, } end |
#to_json ⇒ String
131 132 133 |
# File 'lib/plan_my_stuff/base_metadata.rb', line 131 def to_json(...) to_h.to_json(...) end |
#validate_custom_fields! ⇒ true
Validates custom fields against the schema.
126 127 128 |
# File 'lib/plan_my_stuff/base_metadata.rb', line 126 def validate_custom_fields! custom_fields.validate! if custom_fields.is_a?(PlanMyStuff::CustomFields) end |