Permalink
Browse files

Trying to use tribalvibes' fork of Ohm

  • Loading branch information...
1 parent 0d35240 commit 1e272325c0cca1d6c8eee3c78d2f9d6c1bc6379c @mcmire committed Jun 27, 2012
View
12 Gemfile
@@ -5,11 +5,16 @@ source :rubygems
# right version of Bundler
gem 'bundler', '~> 1.1.0'
-gem 'rails', '3.2.3'
+# gem 'rails', '3.2.3'
+gem 'tzinfo' # activesupport should be requiring this but it doesn't :(
+gem 'activesupport', '3.2.3'
+gem 'actionpack', '3.2.3'
gem 'redis', '3.0.0'
-gem 'ohm', '0.1.5'
-gem 'ohm-contrib', '0.1.2', :require => 'ohm/contrib'
+# gem 'ohm', '0.1.5'
+gem 'ohm-contrib', '1.0.1', :require => false
+# CAN'T USE THIS... IT'S A FORK OF 0.1 AND OHM IS UP TO 1.0 NOW :(
+gem 'ohm', :git => 'http://github.com/tribalvibes/ohm'
#---
@@ -25,7 +30,6 @@ gem 'active_hash', '0.9.10'
gem 'colored', '1.2', :require => false
# Provides String#to_ascii which is useful when screenscraping
gem 'stringex', '1.4.0'
-# gem 'queue_classic', '2.0.0'
gem 'map', '5.7.0'
gem 'logging', '1.7.2'
gem 'logging-rails', '0.4.0'
View
@@ -1,9 +1,13 @@
+GIT
+ remote: http://github.com/tribalvibes/ohm
+ revision: d862f19ffbb60d5958757c9a39ba09a73c37305c
+ specs:
+ ohm (0.1.3)
+ nest (~> 1.0)
+
GEM
remote: http://rubygems.org/
specs:
- actionmailer (3.2.3)
- actionpack (= 3.2.3)
- mail (~> 2.4.4)
actionpack (3.2.3)
activemodel (= 3.2.3)
activesupport (= 3.2.3)
@@ -19,19 +23,10 @@ GEM
activemodel (3.2.3)
activesupport (= 3.2.3)
builder (~> 3.0.0)
- activerecord (3.2.3)
- activemodel (= 3.2.3)
- activesupport (= 3.2.3)
- arel (~> 3.0.2)
- tzinfo (~> 0.3.29)
- activeresource (3.2.3)
- activemodel (= 3.2.3)
- activesupport (= 3.2.3)
activesupport (3.2.3)
i18n (~> 0.6)
multi_json (~> 1.0)
addressable (2.2.8)
- arel (3.0.2)
awesome_print (1.0.2)
bourbon (2.1.0)
sass (>= 3.1)
@@ -77,10 +72,6 @@ GEM
little-plugger (>= 1.1.3)
logging-rails (0.4.0)
logging (~> 1.6)
- mail (2.4.4)
- i18n (>= 0.4.0)
- mime-types (~> 1.16)
- treetop (~> 1.4.8)
map (5.7.0)
method_source (0.7.1)
mime-types (1.18)
@@ -90,11 +81,8 @@ GEM
redis
netrc (0.7.1)
nokogiri (1.5.2)
- ohm (0.1.5)
- nest (~> 1.0)
ohm-contrib (0.1.2)
ohm
- polyglot (0.3.3)
pry (0.9.9.6)
coderay (~> 1.0.5)
method_source (~> 0.7.1)
@@ -106,14 +94,6 @@ GEM
rack
rack-test (0.6.1)
rack (>= 1.0)
- rails (3.2.3)
- actionmailer (= 3.2.3)
- actionpack (= 3.2.3)
- activerecord (= 3.2.3)
- activeresource (= 3.2.3)
- activesupport (= 3.2.3)
- bundler (~> 1.0)
- railties (= 3.2.3)
railties (3.2.3)
actionpack (= 3.2.3)
activesupport (= 3.2.3)
@@ -150,9 +130,6 @@ GEM
rack (>= 1.0.0)
thor (0.14.6)
tilt (1.3.3)
- treetop (1.4.10)
- polyglot
- polyglot (>= 0.3.1)
tzinfo (0.3.33)
uglifier (1.2.4)
execjs (>= 0.3.0)
@@ -163,7 +140,9 @@ PLATFORMS
ruby
DEPENDENCIES
+ actionpack (= 3.2.3)
active_hash (= 0.9.10)
+ activesupport (= 3.2.3)
awesome_print
bourbon (~> 2.1.0)
bundler (~> 1.1.0)
@@ -178,16 +157,16 @@ DEPENDENCIES
map (= 5.7.0)
mustache (= 0.99.4)
nokogiri (= 1.5.2)
- ohm (= 0.1.5)
+ ohm!
ohm-contrib (= 0.1.2)
pry
- rails (= 3.2.3)
redis (= 3.0.0)
sass-rails (~> 3.2.3)
simple-navigation (= 3.7.0)
stache (= 0.9.1)
stringex (= 1.4.0)
therubyracer (~> 0.9.8)
thin (~> 1.3.1)
+ tzinfo
uglifier (>= 1.0.3)
yajl-ruby (= 1.1.0)
View
@@ -1,22 +1,19 @@
class Category < Ohm::Model
include Hardwarepedia::ModelMixins::RequiresFields
- include Ohm::DataTypes
- include Ohm::Timestamps
+ include Ohm::Serialized
+
+ def self.with_chipsets
+ ["Graphics Cards"]
+ end
attribute :name
- attribute :webkey
- attribute :state, Type::Integer
+ attribute :webkey, :default => lambda {|c| c.name.parameterize }
+ attribute :state, :default => 0
unique :name
unique :webkey
requires_fields :name, :webkey, :state
-
- def initialize(attrs={})
- super(attrs)
- self.webkey ||= name.parameterize
- self.state ||= 0
- end
end
View
@@ -1,13 +1,16 @@
class Image < Ohm::Model
- include Hardwarepedia::ModelMixins::RequiresFields
- include Ohm::DataTypes
+ include Ohm::Serialized
include Ohm::Timestamps
+ include Hardwarepedia::ModelMixins::RequiresFields
reference :reviewable, :Reviewable
+ reference :reviewable_url, :Url
attribute :url
attribute :caption
- requires_fields :reviewable_id, :url
+ unique :url
+
+ requires_fields :reviewable_id, :reviewable_url, :url
end
View
@@ -1,20 +1,19 @@
class Manufacturer < Ohm::Model
+ include Hardwarepedia::ModelMixins::RequiresFields
+ include Ohm::Serialized
+
collection :reviewables
collection :products
collection :chipsets
- validates_presence_of :name
- validates_uniqueness_of :name
+ attribute :name
+ attribute :webkey, :default => lambda {|m| m.name.parameterize }
- before_save :_set_webkey
+ requires_fields :name, :webkey
def to_param
webkey
end
-
- def _set_webkey
- self.webkey = name.parameterize
- end
end
View
@@ -1,5 +1,17 @@
-class Price < ActiveRecord::Base
+class Price < Ohm::Model
+ include Ohm::Serialized
+ include Ohm::Timestamps
+ include Hardwarepedia::ModelMixins::RequiresFields
+
+ reference :reviewable, :Reviewable
+ reference :reviewable_url, :Url
+ attribute :amount, Integer
+
+ unique :reviewable_url
+
+ requires_fields :reviewable_id, :reviewable_url, :amount
+
def retailer_name
@retailer_name ||= begin
host = URI.parse(url).host.sub(%r{^www\.}, "")
View
@@ -1,12 +1,11 @@
class Product < Reviewable
- belongs_to :category
- belongs_to :manufacturer
- belongs_to :chipset
+ reference :chipset, :Chipset
- validates_presence_of :chipset_id, :if => [:complete?, :_chipset_needed?]
+ requires_fields :chipset_id,
+ :if => [:complete?, :_chipset_needed?]
def _chipset_needed?
- category.name == "Graphics Cards"
+ Category.with_chipsets.include?(category.name)
end
end
View
@@ -1,9 +1,24 @@
-class Rating < ActiveRecord::Base
- belongs_to :reviewable
+class Rating < Ohm::Model
+ include Ohm::Timestamps
+ include Hardwarepedia::ModelMixins::RequiresFields
+
+ reference :reviewable, :Reviewable
+ attribute :reviewable_url, :Url
+ attribute :raw_value
+ attribute :value, Float
+ attribute :num_reviews, Integer
+
+ unique :reviewable_url
+
+ requires_fields :reviewable_id, :reviewable_url, :raw_value, :value, :num_reviews
before_save :_interpret_raw_value
+ def before_save
+ _interpret_raw_value
+ end
+
def retailer_name
@retailer_name ||= begin
host = URI.parse(url).host.sub(%r{^www\.}, "")
View
@@ -5,44 +5,37 @@ class Reviewable < Ohm::Model
# field that holds info scraped from a URL
include Hardwarepedia::ModelMixins::RequiresFields
- include Ohm::DataTypes
+ include Ohm::Serialized
include Ohm::Timestamps
reference :manufacturer, :Manufacturer
reference :category, :Category
- reference :chipset, :Chipset
attribute :type # one of Chipset or Product
attribute :name
- attribute :full_name
- attribute :webkey
+ attribute :full_name, :default => lambda {|r| manufacturer && [manufacturer.name, name].join(" ") }
+ attribute :webkey, :default => lambda {|r| r.full_name.try(:parameterize) }
attribute :summary
- attribute :num_reviews, Type::Integer
- attribute :specs, Type::Hash
+ attribute :num_reviews, Integer
+ attribute :specs, Hash
set :content_urls
set :official_urls
set :mention_urls
- attribute :market_release_date, Type::Date
- attribute :state, Type::Integer
+ attribute :market_release_date, Date
+ attribute :state, Integer, :default => 0
- collection :images
- collection :prices
- collection :ratings
- collection :reviews
+ set :images, :Image
+ set :prices, :Price
+ set :ratings, :Rating
+ set :reviews, :Review
requires_fields \
:manufacturer_id, :category_id, :name, :first_price, :specs, :content_urls,
:if => :complete?
fails_save_with("Must have one price") {|r| r.prices.empty? }
- def initialize(attrs={})
- super(attrs)
- self.full_name ||= (
- manufacturer && [manufacturer.name, name].join(" ")
- )
- self.webkey ||= full_name.try(:parameterize)
- self.state ||= 0
- end
+ unique :full_name
+ unique :webkey
def incomplete?
state == 0
View
@@ -3,9 +3,9 @@
class Url
include Hardwarepedia::ModelMixins::RequiresFields
- include Ohm::DataTypes
+ include Ohm::Serialized
include Ohm::Timestamps
- include Ohm::Expiration
+ include Ohm::Expiration # our extension
# Delete all urls, or urls of a certain type
def self.delete_all(opts={})
@@ -20,8 +20,10 @@ def self.delete_all(opts={})
attribute :url
attribute :content_html
attribute :content_digest
- attribute :state, Type::Integer
- attribute :last_fetched_at, Type::Time
+ attribute :state, Integer
+ attribute :last_fetched_at, Time
+
+ unique :url
expire_in 2.hours
View
@@ -40,13 +40,13 @@ class Application < Rails::Application
# your app. As such, your models will need to explicitly whitelist or
# blacklist accessible parameters by using an attr_accessible or
# attr_protected declaration.
- config.active_record.whitelist_attributes = false
+ # config.active_record.whitelist_attributes = false
# Enable the asset pipeline
config.assets.enabled = true
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
- config.cache_store = [:file_store, Rails.root.join('tmp/cache'), :expires_in => 1.day]
+ # config.cache_store = [:file_store, Rails.root.join('tmp/cache'), :expires_in => 1.day]
end
end
Oops, something went wrong.

0 comments on commit 1e27232

Please sign in to comment.