class Travis::Client::Entity

Attributes

session[R]

Public Class Methods

add_action(resource_type, name, action, instance_only: false) click to toggle source
# File lib/travis/client/entity.rb, line 9
def self.add_action(resource_type, name, action, instance_only: false)
  if name == action.name and !respond_to?(name, true) and !instance_only
    define_singleton_method(name) { |params = {}| action.call(session, params) }
  end

  if action.instance_action?(resource_type) and not method_defined? name
    define_method(name) { |params = {}| action.call(session, params.merge(resource_type => self)) }
  end
end
add_attribute(name) click to toggle source
# File lib/travis/client/entity.rb, line 4
def self.add_attribute(name)
  define_method(name) { self[name] } unless method_defined? name
  define_method("#{name}?") { !!public_send(name) } unless method_defined? "#{name}?"
end
for_session(session) click to toggle source
# File lib/travis/client/entity.rb, line 30
def self.for_session(session)
  Class.new(self) { define_singleton_method(:session) { session } }
end
new(session, href) click to toggle source
# File lib/travis/client/entity.rb, line 36
def initialize(session, href)
  @session = session
  @href    = href
  @payload = {}
end

Public Instance Methods

[](key) click to toggle source
# File lib/travis/client/entity.rb, line 54
def [](key)
  key = key.to_s

  if @href and type = @payload['@type'] and not @payload.include? key
    href = @href.dup
    href.query_values = { 'include' => "#{type}.#{key}" }
    @session.request('GET', href)
    @payload.fetch(key) { @payload[key] = nil }
  end

  result = @payload[key]
  result = result.fetch if result.is_a? Link
  result
end
inspect() click to toggle source
# File lib/travis/client/entity.rb, line 42
def inspect
  @href ? "#<%p:%p>" % [self.class, @href.path] : "#<%p>" % [self.class]
end
merge!(data) click to toggle source
# File lib/travis/client/entity.rb, line 69
def merge!(data)
  @payload.merge! data
end
permission?(key) click to toggle source
# File lib/travis/client/entity.rb, line 73
def permission?(key)
  Hash(self['@permissions'])[key.to_s]
end
to_entity() click to toggle source
# File lib/travis/client/entity.rb, line 50
def to_entity
  self
end
to_h() click to toggle source
# File lib/travis/client/entity.rb, line 46
def to_h
  @payload.dup
end