class Artifactory::Resource::Base
def attribute(key, default = nil)
-
(Boolean)
- -
(Object)
-
Parameters:
-
default
(Object
) -- -
value
(Object
) --
def attribute(key, default = nil) key = key.to_sym unless key.is_a?(Symbol) # Set this attribute in the top-level hash attributes[key] = nil define_method(key) do value = attributes[key] return value unless value.nil? if default.nil? value elsif default.is_a?(Proc) default.call else default end end define_method("#{key}?") do !!attributes[key] end define_method("#{key}=") do |value| set(key, value) end end
def attributes
-
(Array
-)
def attributes @attributes ||= {} end
def attributes
-
(hash)
-
def attributes @attributes ||= self.class.attributes.dup end
def extract_client!(options)
(**options)
-
:client
(Artifactory::Client
) --
Parameters:
-
options
(Hash
) --
def extract_client!(options) options.delete(:client) || Artifactory.client end
def extract_client!(options)
- See: Resource::Base.extract_client! -
def extract_client!(options) self.class.extract_client!(options) end
def find_from_config(xpath, config, options = {})
-
options
(Hash
) -- -
config
(REXML
) -- -
xpath
(String
) --
def find_from_config(xpath, config, options = {}) name_node = REXML::XPath.match(config, xpath) return nil if name_node.empty? properties = {} name_node[0].parent.each_element_with_text do |e| properties[e.name] = Util.to_type(e.text) end from_hash(properties, options) end
def format_repos!(options)
-
options
(Hash
) --
def format_repos!(options) return options if options[:repos].nil? || options[:repos].empty? options[:repos] = Array(options[:repos]).compact.join(",") options end
def format_repos!(options)
- See: Resource::Base.format_repos! -
def format_repos!(options) self.class.format_repos!(options) end
def from_hash(hash, options = {})
-
(~Resource::Base)
-
Options Hash:
(**options)
-
:client
(Artifactory::Client
) --
Parameters:
-
options
(Hash
) -- -
hash
(Hash
) --
def from_hash(hash, options = {}) instance = new instance.client = extract_client!(options) hash.inject(instance) do |instance, (key, value)| method = :"#{Util.underscore(key)}=" if instance.respond_to?(method) instance.send(method, value) end instance end end
def from_url(url, options = {})
-
(~Resource::Base)
-
Options Hash:
(**options)
-
:client
(Artifactory::Client
) --
Parameters:
-
options
(Hash
) -- -
url
(String
) --
def from_url(url, options = {}) # Parse the URL and only use the path so the configured # endpoint/proxy/SSL settings are used in the GET request. path = URI.parse(url_safe(url)).path client = extract_client!(options) # If the endpoint contains a path part, we must remove the # endpoint path part from path, because the client uses # endpoint + path as its full URI. endpoint_path = URI.parse(client.endpoint).path path.slice!(endpoint_path) from_hash(client.get(path), client: client) end
def has_attribute?(key)
-
(true, false)
-
Parameters:
-
key
(#to_sym
) --
def has_attribute?(key) attributes.has_key?(key.to_sym) end
def initialize(attributes = {})
Create a new instance
def initialize(attributes = {}) attributes.each do |key, value| set(key, value) end end
def inspect
- Private: -
def inspect list = attributes.collect do |key, value| unless Resource::Base.has_attribute?(key) "#{key}: #{value.inspect}" end end.compact "#<#{short_classname} #{list.join(', ')}>" end
def list_from_config(xpath, config, options = {})
-
options
(Hash
) -- -
config
(REXML
) -- -
xpath
(String
) --
def list_from_config(xpath, config, options = {}) REXML::XPath.match(config, xpath).map do |r| hash = {} r.each_element_with_text do |l| hash[l.name] = l.get_text end from_hash(hash, options) end end
def set(key, value)
-
(Object)
-
Parameters:
-
value
(Object
) -- -
key
(#to_sym
) --
def set(key, value) attributes[key.to_sym] = value end
def short_classname
def short_classname @short_classname ||= self.class.name.split("::").last end
def to_hash
-
(Hash)
-
Other tags:
- Example: An example hash response -
def to_hash attributes.inject({}) do |hash, (key, value)| unless Resource::Base.has_attribute?(key) hash[Util.camelize(key, true)] = send(key.to_sym) end hash end end
def to_json
-
(String)
-
Other tags:
- See: Artifactory::Resource::Base#to_json -
def to_json JSON.fast_generate(to_hash) end
def to_matrix_properties(hash = {})
- See: http://bit.ly/1qeVYQl -
def to_matrix_properties(hash = {}) properties = hash.map do |k, v| key = CGI.escape(k.to_s) value = CGI.escape(v.to_s) "#{key}=#{value}" end if properties.empty? nil else ";#{properties.join(';')}" end end
def to_query_string_parameters(hash = {})
- See: http://bit.ly/1qeVYQl -
def to_query_string_parameters(hash = {}) properties = hash.map do |k, v| key = URI.escape(k.to_s) value = URI.escape(v.to_s) "#{key}=#{value}" end if properties.empty? nil else properties.join("&") end end
def to_s
- Private: -
def to_s "#<#{short_classname}>" end
def url_safe(value)
-
(String)
-
Parameters:
-
value
(#to_s
) --
def url_safe(value) URI.escape(URI.unescape(value.to_s)) end
def url_safe(value)
- See: Resource::Base.url_safe -
def url_safe(value) self.class.url_safe(value) end