Module: Ken
- Extended by:
- Extlib::Assertions
- 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/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(<String>)
Ken.logger.error(<String>)
Ken.logger.warn(<String>)
Ken.logger.info(<String>)
Ken.logger.debug(<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, AttributeNotFound, Collection, Logger, Property, PropertyNotFound, ReadError, Resource, ResourceNotFound, Session, Type, View, ViewNotFound
Constant Summary collapse
- FETCH_DATA_QUERY =
store query as a constant here. if the hash gets updated using #merge! or #update, this will mean that it actually stores the last query used. there are 2 sides to this. on the one hand, it isn’t really a constant anymore (ruby doesn’t complain)? on the other hand, there is no need to create a new object everytime a query is executed. maybe this is fine, maybe not, this needs to be discussed.
{ # :id => id, # needs to be merge!d in instance method :guid => nil, :name => nil, :"ken:type" => [{ :id => nil, :name => nil, :properties => [{ :id => nil, :name => nil, :expected_type => nil, :unique => nil, :reverse_property => nil, :master_property => nil, }] }], :"/type/reflect/any_master" => [ { :id => nil, :link => nil, :name => nil, :optional => true } ], :"/type/reflect/any_reverse" => [ { :id => nil, :link => nil, :name => nil, :optional => true } ], :"/type/reflect/any_value" => [ { :link => nil, :value => nil, :optional => true # TODO: support multiple language # :lang => "/lang/en", # :type => "/type/text" } ] }
Class Attribute Summary collapse
-
.logger ⇒ Object
Returns the value of attribute logger.
-
.session ⇒ Object
Returns the value of attribute session.
Class Method Summary collapse
-
.all(options = {}) ⇒ Object
Executes an Mql Query against the Freebase API and returns the result as a
CollectionofResources. -
.get(id) ⇒ Object
Executes an Mql Query against the Freebase API and returns the result wrapped in a
ResourceObject.
Class Attribute Details
.logger ⇒ Object
Returns the value of attribute logger.
37 38 39 |
# File 'lib/ken/logger.rb', line 37 def logger @logger end |
.session ⇒ Object
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
Executes an Mql Query against the Freebase API and returns the result as a Collection of Resources.
performs a cursored query unless there’s a limit specified
Examples
Ken.all(:name => “Apple”, :type => “/music/album”)
Ken.all(
:directed_by => "George Lucas",
:starring => [{
:actor => "Harrison Ford"
}],
:type => "/film/film"
)
102 103 104 105 106 107 |
# File 'lib/ken.rb', line 102 def self.all( = {}) assert_kind_of 'options', , Hash query = { :name => nil }.merge!().merge!(:id => nil) result = Ken.session.mqlread([ query ], :cursor => ![:limit]) Ken::Collection.new(result.map { |r| Ken::Resource.new(r) }) 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">
117 118 119 120 121 122 |
# File 'lib/ken.rb', line 117 def self.get(id) assert_kind_of 'id', id, String result = Ken.session.mqlread(FETCH_DATA_QUERY.merge!(:id => id)) raise ResourceNotFound unless result Ken::Resource.new(result) end |