Skip to content
Browse files

Moves library classes into rdf-virtuoso

  • Loading branch information...
1 parent b30961b commit 9a9e977241b0c3076739ab419a074381423b3612 @pkordel pkordel committed May 15, 2012
Showing with 11 additions and 185 deletions.
  1. +0 −3 Gemfile
  2. +5 −5 Gemfile.lock
  3. +2 −0 app/models/employer.rb
  4. +2 −0 app/models/review.rb
  5. +2 −0 app/models/source.rb
  6. +0 −9 lib/active_rdf/model.rb
  7. +0 −168 lib/active_rdf/persistence.rb
View
3 Gemfile
@@ -58,7 +58,4 @@ gem 'bcrypt-ruby', '~> 3.0.0'
gem 'feedzirra', git: 'git@github.com:pkordel/feedzirra.git'
gem 'capistrano'
gem 'rocket_pants', '~> 1.0'
-gem 'active_attr'
gem 'rdf-virtuoso', path: '../rdf-virtuoso'
-gem 'uuid', '~> 2.3.5'
-gem "transaction-simple", "~> 1.4.0"
View
10 Gemfile.lock
@@ -34,10 +34,13 @@ PATH
remote: ../rdf-virtuoso
specs:
rdf-virtuoso (0.0.1)
+ active_attr
+ activesupport (~> 3.2.3)
api_smith
- httparty
- net-http-persistent
+ httparty (= 0.8.2)
rdf (~> 0.3.5)
+ transaction-simple (~> 1.4.0)
+ uuid (~> 2.3.5)
GEM
remote: https://rubygems.org/
@@ -287,7 +290,6 @@ PLATFORMS
ruby
DEPENDENCIES
- active_attr
bcrypt-ruby (~> 3.0.0)
bootstrap-sass
capistrano
@@ -319,7 +321,5 @@ DEPENDENCIES
sparql-client!
sqlite3
thin
- transaction-simple (~> 1.4.0)
uglifier (>= 1.0.3)
- uuid (~> 2.3.5)
vcr
View
2 app/models/employer.rb
@@ -1,3 +1,5 @@
+require 'active_rdf'
+
class Employer < ActiveRDF::Model
validates :name, presence: true
View
2 app/models/review.rb
@@ -1,3 +1,5 @@
+require 'active_rdf'
+
class Review < ActiveRDF::Model
#belongs_to :source
View
2 app/models/source.rb
@@ -1,3 +1,5 @@
+require 'active_rdf'
+
class Source < ActiveRDF::Model
#has_many :reviews
View
9 lib/active_rdf/model.rb
@@ -1,9 +0,0 @@
-module ActiveRDF
-
- class Model
- include ActiveAttr::Model
- include ActiveModel::Dirty
- include ActiveRDF::Persistence
-
- end
-end
View
168 lib/active_rdf/persistence.rb
@@ -1,168 +0,0 @@
-module ActiveRDF
- module Persistence
- extend ActiveSupport::Concern
-
- included do
-
- # Override ActiveAttr::Attributes.attribute=(name, value)
- def attribute=(name, value)
- @attributes ||= {}
- send("#{name}_will_change!") unless @attributes[name] == value
- @attributes[name] = value
- end
- end
-
- module ClassMethods
-
- def graph
- url = RDF::URI.new("http://data.deichman.no")
- url = url.join Rails.env unless Rails.env.production?
- url / self.name.downcase.pluralize
- end
-
- def create(attrs = nil)
- object = new(attrs)
- object.save
- object
- end
-
- def create!(attrs = nil)
- object = new(attrs)
- object.save!
- object
- end
-
- def before_create(method)
- end
-
- def before_save(method)
- end
-
- # @see: http://rdf.rubyforge.org/RDF/Query/Solutions.html
- def order(variable)
- end
-
- def where(conditions)
- end
-
- def scope(variable, conditions)
- end
-
- def scoped
- end
-
- def count
- query = "SELECT COUNT(DISTINCT ?s) WHERE { GRAPH <#{self.graph}> { ?s a <#{self.type}> }}"
- result = CLIENT.select(query)
- result.first['callret-0'].to_i
- end
-
- def execute(sql)
- results = []
- solutions = CLIENT.select(sql)
- solutions.each do |solution|
- record = new
- solution.each_binding do |name, value|
- record[name] = value.to_s.blank? ? nil : value.to_s
- end
- record.id = id_for(record.id)
- record.changed_attributes.clear
- results << record
- end
- results
- end
-
- def subject_for(id)
- "<" << (self.graph / "#" / id) << ">"
- end
-
- def id_for(subject)
- subject.to_s.gsub((self.graph / '#').to_s, '')
- end
-
- def destroy_all
- query = "CLEAR GRAPH <#{self.graph}>"
- CLIENT.clear(query)
- end
- end
-
- # Instance methods
- def to_param
- self.id.gsub((self.class.graph / '#').to_s, '')
- end
-
- def type
- self.class.type
- end
-
- def graph
- self.class.graph
- end
-
- def save
- return false unless self.valid?
- create_or_update
- end
-
- def save!
- unless self.valid?
- raise ActiveRecord::RecordInvalid.new(self)
- end
- create_or_update
- end
-
- def destroy
-
- subject = subject_for(self.id)
-
- query = "DELETE FROM <#{self.class.graph}> { #{subject} ?p ?o } WHERE { #{subject} ?p ?o }"
-
- result = CLIENT.delete(query)
- end
-
-
- def update_attributes(attributes)
- self.extend(::Transaction::Simple)
- status = false
- begin
- self.start_transaction
- self.assign_attributes(attributes)
- status = save
- self.commit_transaction
- rescue Exception
- self.rewind_transaction
- self.abort_transaction
- end
- status
- end
-
- def reload
- self.attributes = self.class.find(self.id).attributes
- self
- end
-
- def new_record?
- self.id.nil?
- end
-
- def persisted?
- !new_record?
- end
-
- private
-
- def subject_for(id)
- self.class.subject_for(id)
- end
-
- def create_or_update
- result = new_record? ? create : update
- result != false
- end
-
- def guid
- UUID.generate(:compact)
- end
-
- end
-end

0 comments on commit 9a9e977

Please sign in to comment.
Something went wrong with that request. Please try again.