Module: Ken

Defined in:
lib/ken/view.rb,
lib/ken.rb,
lib/ken/type.rb,
lib/ken/util.rb,
lib/ken/logger.rb,
lib/ken/session.rb,
lib/ken/version.rb,
lib/ken/property.rb,
lib/ken/resource.rb,
lib/ken/attribute.rb,
lib/ken/collection.rb

Overview

Public Ken Logger API

Logger taken from Merb/Datamapper :)

To replace an existing logger with a new one:

Ken.logger.set_log(log{String, IO},level{Symbol, String})

Available logging levels are:

:off, :fatal, :error, :warn, :info, :debug

Logging via:

Ken.logger.fatal(message<String>)
Ken.logger.error(message<String>)
Ken.logger.warn(message<String>)
Ken.logger.info(message<String>)
Ken.logger.debug(message<String>)

Flush the buffer to

Ken.logger.flush

Remove the current log object

Ken.logger.close

Private Ken Logger API

To initialize the logger you create a new object, proxies to set_log.

ken::Logger.new(log{String, IO}, level{Symbol, String})

Logger will not create the file until something is actually logged This avoids file creation on Ken init when it creates the default logger.

Defined Under Namespace

Modules: Util Classes: Attribute, Collection, Logger, Property, ReadError, Resource, Session, Type, View

Constant Summary collapse

VERSION =
'0.0.2'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.loggerObject

Returns the value of attribute logger.



37
38
39
# File 'lib/ken/logger.rb', line 37

def logger
  @logger
end

.sessionObject

Returns the value of attribute session.



3
4
5
# File 'lib/ken/session.rb', line 3

def session
  @session
end

Class Method Details

.all(options = {}) ⇒ Object

Raises:

  • (NotImplementedError)


28
29
30
31
# File 'lib/ken.rb', line 28

def self.all(options = {})
  # raise ArgumentError.new("must be a hash") unless options.is_a(::Hash)
  raise NotImplementedError
end

.get(id) ⇒ Object

Executes an Mql Query against the Freebase API and returns the result wrapped in a Resource Object.

Examples

Ken.get('/en/the_police') => #<Resource id="/en/the_police" name="The Police">

Raises:

  • (ArgumentError)


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/ken.rb', line 40

def self.get(id)
  # TODO check if it has a correct /type/object/id syntax
  raise ArgumentError.new("must be a string") unless id.is_a?(::String)
  
  query = {
    :id => id,
    :name => nil,
    :type => [{
      :id => nil,
      :name => nil,
      :properties => [{
        :id => nil,
        :name => nil,
        :expected_type => nil,
        :unique => nil,
        :reverse_property => nil,
        :master_property => nil,
      }]
    }]
  }
  
  result = Ken.session.mqlread(query)
  return Ken::Resource.new(result)
end