spleen 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
@@ -4,6 +4,31 @@
4
4
 
5
5
  bundle exec rails generate spleen:install
6
6
 
7
+ Usage:
8
+
9
+ # edit app/models/article.rb:
10
+ extend Spleen
11
+ spleen(:dependent => :destroy)
12
+
13
+ # add Article to RATEABLE_TYPES on app/models/rating.rb:
14
+ RATEABLE_TYPES = %w{Article}
15
+
16
+ a = Article.create(:title => 'test')
17
+ a.rate(1, User.last)
18
+ a.ratings # => [#<Rating id: 1, ...]
19
+ a.average_rate # => 1.0
20
+ a.sum_rate # => 1
21
+ a.count_rate # => 1
22
+
23
+ # Tests
24
+
25
+ bundle exec ruby test/*_test.rb
26
+
27
+ # TODO
28
+
29
+ * tests
30
+ * documentation
31
+
7
32
  # LICENSE
8
33
 
9
34
  The MIT License
@@ -11,7 +11,7 @@ module Spleen
11
11
  class_option :orm
12
12
 
13
13
  def copy_locale
14
- copy_file "../../../../config/locales/en.yml", "config/locales/ratings.en.yml"
14
+ copy_file "locales.en.yml", "config/locales/ratings.en.yml"
15
15
  end
16
16
 
17
17
  def copy_model
@@ -7,12 +7,12 @@ In your ratable models:
7
7
  extend Spleen
8
8
  spleen(:dependent => :destroy)
9
9
 
10
- Add your Rateable types in app/models/ratings.rb:
10
+ Add your Rateable types in app/models/rating.rb:
11
11
  RATEABLE_TYPES = %w{SomeRateableClass}
12
12
 
13
13
  By default the ratetor is User, you can add some or edit in the same file.
14
14
 
15
- Examples:
15
+ Usage:
16
16
 
17
17
  a = Article.create(:title => 'test')
18
18
  a.rate(1, User.last)
@@ -1,7 +1,8 @@
1
1
  # encoding: UTF-8
2
- require 'rails'
3
-
4
2
  module Spleen
3
+
4
+ VERSION = '0.0.2'
5
+
5
6
  def self.extended(model_class)
6
7
  model_class.instance_eval do
7
8
  extend Base
@@ -1,8 +1,9 @@
1
1
  # encoding: UTF-8
2
+ require './lib/spleen'
2
3
 
3
4
  Gem::Specification.new do |s|
4
5
  s.name = "spleen"
5
- s.version = '0.0.1'
6
+ s.version = Spleen::VERSION
6
7
  s.platform = Gem::Platform::RUBY
7
8
  s.summary = "Ratings solution for Rails"
8
9
  s.email = "laurent@spkdev.net"
@@ -10,6 +11,11 @@ Gem::Specification.new do |s|
10
11
  s.description = "Ratings model solution for Rails"
11
12
  s.authors = ['Laurent Arnoud']
12
13
 
14
+ s.add_development_dependency "activerecord", "~> 3.1"
15
+ s.add_development_dependency "sqlite3", "~> 1.3"
16
+ s.add_development_dependency "minitest", "~> 2.4.0"
17
+ s.add_development_dependency "i18n", "~> 0.6.0"
18
+
13
19
  s.files = `git ls-files`.split("\n")
14
20
  #s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
21
  s.require_paths = ["lib"]
@@ -0,0 +1,24 @@
1
+ # encoding: UTF-8
2
+ require File.expand_path("../test_helper.rb", __FILE__)
3
+
4
+ class Article < ActiveRecord::Base
5
+ extend Spleen
6
+ spleen(:dependent => :destroy)
7
+ end
8
+
9
+ describe Spleen::Base do
10
+ it 'models dont use spleen by default' do
11
+ assert !ActiveRecord::Base.respond_to?(:spleen)
12
+ assert !Class.new(ActiveRecord::Base).respond_to?(:ratings)
13
+ end
14
+
15
+ it 'have ratings methods' do
16
+ assert Article.respond_to?(:spleen)
17
+ a = Article.new
18
+ assert a.respond_to?(:ratings)
19
+ assert a.respond_to?(:rate)
20
+ assert a.respond_to?(:average_rate)
21
+ assert a.respond_to?(:sum_rate)
22
+ assert a.respond_to?(:count_rate)
23
+ end
24
+ end
@@ -0,0 +1,4 @@
1
+ sqlite3:
2
+ adapter: sqlite3
3
+ database: ":memory:"
4
+ encoding: utf8
@@ -0,0 +1,29 @@
1
+ # encoding: UTF-8
2
+ $: << File.expand_path("../../lib", __FILE__)
3
+ $: << File.expand_path("../", __FILE__)
4
+ $:.uniq!
5
+ require 'minitest/autorun'
6
+ require 'active_record'
7
+
8
+ require 'spleen'
9
+
10
+ # If you want to see the ActiveRecord log, invoke the tests using `rake test LOG=true`
11
+ if ENV["LOG"]
12
+ require "logger"
13
+ ActiveRecord::Base.logger = Logger.new($stdout)
14
+ end
15
+
16
+ driver = "sqlite3"
17
+ config = YAML.load_file(File.expand_path("../databases.yml", __FILE__))
18
+ ActiveRecord::Base.establish_connection config[driver]
19
+ ActiveRecord::Migration.verbose = false
20
+
21
+ require 'generators/spleen/templates/migration'
22
+ CreateRatings.up
23
+
24
+ %w{articles}.each do |table_name|
25
+ ActiveRecord::Migration.create_table table_name do |t|
26
+ t.string :name
27
+ t.boolean :active
28
+ end
29
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spleen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,22 +10,70 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
  date: 2011-09-07 00:00:00.000000000Z
13
- dependencies: []
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activerecord
16
+ requirement: &19456960 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.1'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *19456960
25
+ - !ruby/object:Gem::Dependency
26
+ name: sqlite3
27
+ requirement: &19456460 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '1.3'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *19456460
36
+ - !ruby/object:Gem::Dependency
37
+ name: minitest
38
+ requirement: &19455960 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 2.4.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *19455960
47
+ - !ruby/object:Gem::Dependency
48
+ name: i18n
49
+ requirement: &19455480 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.6.0
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *19455480
14
58
  description: Ratings model solution for Rails
15
59
  email: laurent@spkdev.net
16
60
  executables: []
17
61
  extensions: []
18
62
  extra_rdoc_files: []
19
63
  files:
64
+ - Gemfile
20
65
  - LICENSE
21
66
  - README.markdown
22
- - config/locales/en.yml
23
67
  - lib/generators/spleen/install_generator.rb
24
68
  - lib/generators/spleen/templates/README
69
+ - lib/generators/spleen/templates/locales.en.yml
25
70
  - lib/generators/spleen/templates/migration.rb
26
71
  - lib/generators/spleen/templates/model.rb
27
72
  - lib/spleen.rb
28
73
  - spleen.gemspec
74
+ - test/base_test.rb
75
+ - test/databases.yml
76
+ - test/test_helper.rb
29
77
  homepage: http://github.com/spk/spleen
30
78
  licenses: []
31
79
  post_install_message: