Class: JIRA::Resource::Properties
- Defined in:
- lib/jira/resource/properties.rb
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
Instance Method Summary collapse
-
#save!(attrs = {}, path = nil) ⇒ Object
Override save so we can handle the required attrs (and default ‘value’ when appropriate).
Methods inherited from Base
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, hash_to_query_string, #id, #initialize, #key_value, maybe_nested_attribute, #method_missing, nested_collections, #new_record?, parse_json, #patched_url, #path_component, query_params_for_search, query_params_for_single_fetch, #respond_to?, #save, #set_attrs, #set_attrs_from_response, singular_path, #to_json, #to_s, #to_sym, #url, url_with_query_params
Constructor Details
This class inherits a constructor from JIRA::Base
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class JIRA::Base
Class Method Details
.all(client, options = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/jira/resource/properties.rb', line 17 def self.all(client, = {}) issue = [:issue] raise ArgumentError, 'parent issue is required' unless issue response = client.get("#{issue.url}/#{endpoint_name}") json = parse_json(response.body) json[key_attribute.to_s.pluralize].map do |attrs| ## Net get the individual property self_response = client.get(attrs['self']) property = parse_json(self_response.body) ## Make sure to build the new resource via the issue.properties in order to support the has_many proxy issue.properties.build(property) end end |
.key_attribute ⇒ Object
13 14 15 |
# File 'lib/jira/resource/properties.rb', line 13 def self.key_attribute :key end |
Instance Method Details
#save!(attrs = {}, path = nil) ⇒ Object
Override save so we can handle the required attrs (and default ‘value’ when appropriate)
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/jira/resource/properties.rb', line 33 def save!(attrs = {}, path = nil) if attrs.is_a?(Hash) && attrs.key?(self.class.key_attribute.to_s) raise ArgumentError, "Use of 'value' is required when '#{self.class.key_attribute}' is provided" \ unless attrs.key?('value') set_attrs(self.class.key_attribute.to_s => attrs[self.class.key_attribute.to_s]) end raise ArgumentError, "'key' is required on a new record" if new_record? path ||= patched_url ## We can take either the 'value' element from the hash, OR use the entire attrs as the value value = attrs.is_a?(Hash) && attrs.key?('value') ? attrs['value'] : attrs value = '' if value.nil? ## Note: this API endpoint requires a non-empty JSON body for the value of the property ## Note2: this API endpoint does not return a body, so no need to call set_attrs_from_response client.send(:put, path, value.to_json) set_attrs({ 'value' => value }, false) @expanded = false true end |