Class: Checkoff::CustomFields
- Inherits:
-
Object
- Object
- Checkoff::CustomFields
- Extended by:
- CacheMethod::ClassMethods
- Defined in:
- lib/checkoff/custom_fields.rb,
sig/checkoff.rbs
Overview
Work with custom fields in Asana
Constant Summary collapse
- MINUTE =
60- HOUR =
MINUTE * 60
- DAY =
24 * HOUR
- REALLY_LONG_CACHE_TIME =
HOUR- LONG_CACHE_TIME =
MINUTE * 15
- SHORT_CACHE_TIME =
MINUTE
Instance Attribute Summary collapse
-
#client ⇒ Asana::Client
readonly
sord warn - Asana::Client wasn't able to be resolved to a constant in this project.
- #workspaces ⇒ Checkoff::Workspaces readonly
Class Method Summary collapse
Instance Method Summary collapse
-
#custom_field(workspace_name, custom_field_name) ⇒ Asana::Resources::CustomField?
sord warn - Asana::Resources::CustomField wasn't able to be resolved to a constant in this project @param
workspace_name. -
#custom_field_or_raise(workspace_name, custom_field_name) ⇒ Asana::Resources::CustomField
sord warn - Asana::Resources::CustomField wasn't able to be resolved to a constant in this project @sg-ignore nil check above is not flow-sensitive.
-
#find_gids(custom_field, enum_value) ⇒ ::Array[String]
@param
custom_field. -
#initialize(config: Checkoff::Internal::ConfigLoader.load(:asana), clients: Checkoff::Clients.new(config:), client: clients.client, workspaces: Checkoff::Workspaces.new(config:, client:)) ⇒ Object
constructor
sord warn - Asana::Client wasn't able to be resolved to a constant in this project @param
config. -
#resource_custom_field_by_gid_or_raise(resource, custom_field_gid) ⇒ ::Hash[untyped, untyped]
sord warn - Asana::Resources::Project wasn't able to be resolved to a constant in this project sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project @sg-ignore nil check above is not flow-sensitive.
-
#resource_custom_field_by_name(resource, custom_field_name) ⇒ ::Hash[untyped, untyped]?
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project sord warn - Asana::Resources::Project wasn't able to be resolved to a constant in this project @param
resource. -
#resource_custom_field_by_name_or_raise(resource, custom_field_name) ⇒ ::Hash[untyped, untyped]
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project sord warn - Asana::Resources::Project wasn't able to be resolved to a constant in this project @sg-ignore nil check above is not flow-sensitive.
-
#resource_custom_field_enum_values(custom_field) ⇒ ::Array[::Hash[untyped, untyped]]
@sg-ignore Declared return type Array
does not match inferred type Array,Hash,Array — fixing cleanly needs restructuring the case/when to bind each branch to a typed local; leaving for a follow-up code PR to keep this one annotation-only. -
#resource_custom_field_values_gids_or_raise(resource, custom_field_gid) ⇒ ::Array[String]
sord warn - Asana::Resources::Project wasn't able to be resolved to a constant in this project sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project @param
resource. -
#resource_custom_field_values_names_by_name(resource, custom_field_name) ⇒ ::Array[String]
sord warn - Asana::Resources::Project wasn't able to be resolved to a constant in this project sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project @sg-ignore Declared return type Array
does not match inferred type Array,Array — fixing cleanly needs binding enum_value.fetch('name') to a typed local; leaving for a follow-up code PR to keep this one annotation-only.
Constructor Details
#initialize(config: Checkoff::Internal::ConfigLoader.load(:asana), clients: Checkoff::Clients.new(config:), client: clients.client, workspaces: Checkoff::Workspaces.new(config:, client:)) ⇒ Object
sord warn - Asana::Client wasn't able to be resolved to a constant in this project
@param config
@param workspaces
@param clients
@param client
31 32 33 34 35 36 37 38 |
# File 'lib/checkoff/custom_fields.rb', line 31 def initialize(config: Checkoff::Internal::ConfigLoader.load(:asana), clients: Checkoff::Clients.new(config:), client: clients.client, workspaces: Checkoff::Workspaces.new(config:, client:)) @workspaces = workspaces @client = client end |
Instance Attribute Details
#client ⇒ Asana::Client (readonly)
sord warn - Asana::Client wasn't able to be resolved to a constant in this project
181 182 183 |
# File 'lib/checkoff/custom_fields.rb', line 181 def client @client end |
#workspaces ⇒ Checkoff::Workspaces (readonly)
178 179 180 |
# File 'lib/checkoff/custom_fields.rb', line 178 def workspaces @workspaces end |
Class Method Details
.run ⇒ void
This method returns an undefined value.
187 188 189 190 191 192 193 194 195 |
# File 'lib/checkoff/custom_fields.rb', line 187 def run # @type [String] workspace_name = ARGV[0] || raise('Please pass workspace name as first argument') # @type [String] custom_field_name = ARGV[1] || raise('Please pass custom_field name as second argument') custom_fields = Checkoff::CustomFields.new custom_field = custom_fields.custom_field_or_raise(workspace_name, custom_field_name) puts "Results: #{custom_field}" end |
Instance Method Details
#custom_field(workspace_name, custom_field_name) ⇒ Asana::Resources::CustomField?
sord warn - Asana::Resources::CustomField wasn't able to be resolved to a constant in this project
@param workspace_name
@param custom_field_name
57 58 59 60 61 |
# File 'lib/checkoff/custom_fields.rb', line 57 def custom_field(workspace_name, custom_field_name) workspace = workspaces.workspace_or_raise(workspace_name) custom_fields = client.custom_fields.get_custom_fields_for_workspace(workspace_gid: workspace.gid) custom_fields.find { |custom_field| custom_field.name == custom_field_name } end |
#custom_field_or_raise(workspace_name, custom_field_name) ⇒ Asana::Resources::CustomField
sord warn - Asana::Resources::CustomField wasn't able to be resolved to a constant in this project @sg-ignore nil check above is not flow-sensitive
@param workspace_name
@param custom_field_name
45 46 47 48 49 50 |
# File 'lib/checkoff/custom_fields.rb', line 45 def custom_field_or_raise(workspace_name, custom_field_name) cf = custom_field(workspace_name, custom_field_name) raise "Could not find custom_field #{custom_field_name} under workspace #{workspace_name}." if cf.nil? cf end |
#find_gids(custom_field, enum_value) ⇒ ::Array[String]
@param custom_field
@param enum_value
169 170 171 172 173 174 175 |
# File 'lib/checkoff/custom_fields.rb', line 169 def find_gids(custom_field, enum_value) if enum_value.nil? [] else [enum_value.fetch('gid')] end end |
#resource_custom_field_by_gid_or_raise(resource, custom_field_gid) ⇒ ::Hash[untyped, untyped]
sord warn - Asana::Resources::Project wasn't able to be resolved to a constant in this project sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project @sg-ignore nil check above is not flow-sensitive
@param resource
@param custom_field_gid
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/checkoff/custom_fields.rb', line 129 def resource_custom_field_by_gid_or_raise(resource, custom_field_gid) # @type [Array<Hash>] custom_fields = resource.custom_fields if custom_fields.nil? raise "Could not find custom_fields under project (was 'custom_fields' included in 'extra_fields'?)" end # @type [Hash, nil] matched_custom_field = custom_fields.find { |data| data.fetch('gid') == custom_field_gid } if matched_custom_field.nil? raise "Could not find custom field with gid #{custom_field_gid} " \ "in gid #{resource.gid} with custom fields #{custom_fields}" end matched_custom_field end |
#resource_custom_field_by_name(resource, custom_field_name) ⇒ ::Hash[untyped, untyped]?
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project
sord warn - Asana::Resources::Project wasn't able to be resolved to a constant in this project
@param resource
@param custom_field_name
101 102 103 104 105 106 107 108 109 110 |
# File 'lib/checkoff/custom_fields.rb', line 101 def resource_custom_field_by_name(resource, custom_field_name) # @type [Array<Hash>] custom_fields = resource.custom_fields if custom_fields.nil? raise "custom fields not found on resource - did you add 'custom_fields' in your extra_fields argument?" end # @type [Hash, nil] custom_fields.find { |field| field.fetch('name') == custom_field_name } end |
#resource_custom_field_by_name_or_raise(resource, custom_field_name) ⇒ ::Hash[untyped, untyped]
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project sord warn - Asana::Resources::Project wasn't able to be resolved to a constant in this project @sg-ignore nil check above is not flow-sensitive
@param resource
@param custom_field_name
116 117 118 119 120 121 122 123 |
# File 'lib/checkoff/custom_fields.rb', line 116 def resource_custom_field_by_name_or_raise(resource, custom_field_name) custom_field = resource_custom_field_by_name(resource, custom_field_name) if custom_field.nil? raise "Could not find custom field with name #{custom_field_name} " \ "in gid #{resource.gid} with custom fields #{resource.custom_fields}" end custom_field end |
#resource_custom_field_enum_values(custom_field) ⇒ ::Array[::Hash[untyped, untyped]]
@sg-ignore Declared return type Array
@param custom_field
154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/checkoff/custom_fields.rb', line 154 def resource_custom_field_enum_values(custom_field) resource_subtype = custom_field.fetch('resource_subtype') case resource_subtype when 'enum' [custom_field.fetch('enum_value')] when 'multi_enum' custom_field.fetch('multi_enum_values') else raise "Teach me how to handle resource_subtype #{resource_subtype}" end end |
#resource_custom_field_values_gids_or_raise(resource, custom_field_gid) ⇒ ::Array[String]
sord warn - Asana::Resources::Project wasn't able to be resolved to a constant in this project
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project
@param resource
@param custom_field_gid
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/checkoff/custom_fields.rb', line 68 def resource_custom_field_values_gids_or_raise(resource, custom_field_gid) custom_field = resource_custom_field_by_gid_or_raise(resource, custom_field_gid) resource_custom_field_enum_values(custom_field).flat_map do |enum_value| find_gids(custom_field, enum_value) end rescue StandardError => e raise "Could not process custom field with gid #{custom_field_gid} " \ "in gid #{resource.gid} with custom fields #{resource.custom_fields.inspect}: #{e}" end |
#resource_custom_field_values_names_by_name(resource, custom_field_name) ⇒ ::Array[String]
sord warn - Asana::Resources::Project wasn't able to be resolved to a constant in this project
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project
@sg-ignore Declared return type Array
@param resource
@param custom_field_name
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/checkoff/custom_fields.rb', line 85 def resource_custom_field_values_names_by_name(resource, custom_field_name) custom_field = resource_custom_field_by_name(resource, custom_field_name) return [] if custom_field.nil? resource_custom_field_enum_values(custom_field).flat_map do |enum_value| if enum_value.nil? [] else [enum_value.fetch('name')] end end end |