module SFKB::Decoration

Methods to smartly apply singleton methods to REST objects

Public Instance Methods

autodefine(object) click to toggle source
# File lib/sfkb/decoration.rb, line 24
def autodefine(object)
  return unless object.respond_to?(:additionalInformation)
  return unless info = object.additionalInformation
  autodefine_data(object, info[:data])
  autodefine_links(object, info[:urls])
  autodefine_predicates(object, info)
  object
end
autodefine_data(object, data) click to toggle source
# File lib/sfkb/decoration.rb, line 41
def autodefine_data(object, data)
  return object if data.nil?
  define_link(object, :data, data)
  object
end
autodefine_predicates(object, predicates) click to toggle source
# File lib/sfkb/decoration.rb, line 33
def autodefine_predicates(object, predicates)
  predicates.each do |k, v|
    next unless [true, false].include?(v)
    define_predicate(object, k, v)
  end
  object
end
decorate(object) { |object| ... } click to toggle source
# File lib/sfkb/decoration.rb, line 4
def decorate(object)
  return object unless block_given?
  yield object
  object
end
define_predicate(object, name, value) click to toggle source
# File lib/sfkb/decoration.rb, line 20
def define_predicate(object, name, value)
  object.define_singleton_method(:"#{name}?") { value }
end