Class: JIRA::Resource::Field
Constant Summary
Constants inherited from Base
Base::QUERY_PARAMS_FOR_SEARCH, Base::QUERY_PARAMS_FOR_SINGLE_FETCH
Instance Attribute Summary
Attributes inherited from Base
#attrs, #client, #deleted, #expanded
Class Method Summary collapse
- .field_map(client) ⇒ Object
- .map_fields(client) ⇒ Object
- .name_to_id(client, field_name) ⇒ Object
-
.safe_name(description) ⇒ Object
translate a custom field description to a method-safe name.
-
.safer_name(description, jira_id) ⇒ Object
safe_name plus disambiguation if it fails it uses the original jira id (customfield_#####).
Instance Method Summary collapse
- #method_missing(method_name, *args) ⇒ Object
- #respond_to?(method_name, _include_all = false) ⇒ Boolean
Methods inherited from Base
all, belongs_to, belongs_to_relationships, build, collection_attributes_are_nested, #collection_path, collection_path, #delete, endpoint_name, #fetch, find, #has_errors?, has_many, has_one, #id, #initialize, key_attribute, #key_value, nested_collections, #new_record?, parse_json, #patched_url, #path_component, #save, #save!, #set_attrs, #set_attrs_from_response, singular_path, #to_json, #to_s, #to_sym, #url
Constructor Details
This class inherits a constructor from JIRA::Base
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/jira/resource/field.rb', line 70 def method_missing(method_name, *args, &) if attrs.key?(method_name.to_s) attrs[method_name.to_s] else official_name = client.Field.name_to_id(method_name) if attrs.key?(official_name) attrs[official_name] else super end end end |
Class Method Details
.field_map(client) ⇒ Object
51 52 53 |
# File 'lib/jira/resource/field.rb', line 51 def self.field_map(client) client.field_map_cache end |
.map_fields(client) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/jira/resource/field.rb', line 22 def self.map_fields(client) field_map = {} fields = client.Field.all # two pass approach, so that a custom field with the same name # as a system field can't take precedence fields.each do |f| next if f.custom name = safe_name(f.name) field_map[name] = f.id end fields.each do |f| # rubocop:disable Style/CombinableLoops next unless f.custom name = if field_map.key? f.name renamed = safer_name(f.name, f.id) warn "Duplicate Field name #{f.name} #{f.id} - renaming as #{renamed}" renamed else safe_name(f.name) end field_map[name] = f.id end client.field_map_cache = field_map end |
.name_to_id(client, field_name) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/jira/resource/field.rb', line 55 def self.name_to_id(client, field_name) field_name = field_name.to_s return field_name unless client.field_map_cache && client.field_map_cache[field_name] client.field_map_cache[field_name] end |
.safe_name(description) ⇒ Object
translate a custom field description to a method-safe name
11 12 13 |
# File 'lib/jira/resource/field.rb', line 11 def self.safe_name(description) description.gsub(/[^a-zA-Z0-9]/, '_') end |
.safer_name(description, jira_id) ⇒ Object
safe_name plus disambiguation if it fails it uses the original jira id (customfield_#####)
16 17 18 19 20 |
# File 'lib/jira/resource/field.rb', line 16 def self.safer_name(description, jira_id) "#{safe_name(description)}_#{jira_id.split('_')[1]}" rescue StandardError jira_id end |
Instance Method Details
#respond_to?(method_name, _include_all = false) ⇒ Boolean
62 63 64 65 66 67 68 |
# File 'lib/jira/resource/field.rb', line 62 def respond_to?(method_name, _include_all = false) if [method_name.to_s, client.Field.name_to_id(method_name)].any? { |k| attrs.key?(k) } true else super(method_name) end end |