class Phabulous::Entity
Attributes
phid[RW]
Public Class Methods
all()
click to toggle source
# File lib/phabulous/entity.rb, line 13 def self.all @all ||= Phabulous.conduit.request("#{conduit_name}.query").collect do |attributes| # Some conduit.query calls come back as plain arrays like # [ # { # attr: 1 # }, # { # } # ] # as # { # phid => { # attr1: x, # ... # }, # phid-2 => { # attr2: y # } # } # # This code attempts to handle both cases if attributes.length == 2 && attributes.first.is_a?(String) && attributes.first =~ /^PHID.*$/ new(attributes.last) else new(attributes) end end end
attr_accessor(*args)
click to toggle source
Calls superclass method
# File lib/phabulous/entity.rb, line 3 def self.attr_accessor(*args) @attributes ||= [] @attributes |= args super(*args) end
attributes()
click to toggle source
# File lib/phabulous/entity.rb, line 9 def self.attributes @attributes end
conduit_name()
click to toggle source
# File lib/phabulous/entity.rb, line 63 def self.conduit_name name.demodulize.downcase end
find(id)
click to toggle source
# File lib/phabulous/entity.rb, line 44 def self.find(id) all.select { |entity| entity.phid == id }.first end
new(attributes = {})
click to toggle source
# File lib/phabulous/entity.rb, line 48 def initialize(attributes = {}) attributes.each do |attr, value| send("#{attr}=", value) if respond_to?("#{attr}=") end unless attributes.nil? end
Public Instance Methods
attributes()
click to toggle source
# File lib/phabulous/entity.rb, line 54 def attributes self.class.attributes.inject({}) do |memo, attr| memo[attr] = send(attr) if respond_to?(attr) memo end if self.class.attributes end