positioned 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "http://rubygems.org"
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Arend Miller, Neal White, Cohesive Creative and Code, Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,22 @@
1
+ require 'rails'
2
+ require 'positioned'
3
+
4
+ module Positioned
5
+ if defined? Rails::Railtie
6
+
7
+ class Railtie < Rails::Railtie
8
+
9
+ initializer 'positioned.insert_into_active_record' do
10
+ ActiveSupport.on_load(:active_record) do
11
+ Positioned::Railtie.insert
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+ class Railtie
18
+ def self.insert
19
+ ActiveRecord::Base.send(:include, Positioned::Glue)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module Positioned
2
+ VERSION = "0.0.1"
3
+ end
data/lib/positioned.rb ADDED
@@ -0,0 +1,52 @@
1
+ require "positioned/railtie"
2
+
3
+ # Positioned
4
+ module Positioned #:nodoc:
5
+
6
+ module Glue
7
+ def self.included base
8
+ base.class_eval do
9
+ extend ClassMethods
10
+ end
11
+ end
12
+ end
13
+
14
+ module ClassMethods
15
+ def positioned(options = {})
16
+ options = {:position_column => 'position', :scope_conditions => nil}.update(options)
17
+
18
+ @position_column = options[:position_column]
19
+
20
+ # position scope is to limit the position to certain conditions
21
+ @position_scope = options[:scope_conditions]
22
+ include InstanceMethods
23
+
24
+ before_create :set_position
25
+ end
26
+
27
+ def position_column
28
+ @position_column || nil
29
+ end
30
+ def position_scope
31
+ @position_scope || nil
32
+ end
33
+
34
+ def sorted
35
+ order("#{self.position_column}")
36
+ end
37
+ end
38
+
39
+ module InstanceMethods
40
+
41
+
42
+ def position_column
43
+ self.class.position_column
44
+ end
45
+
46
+ def set_position
47
+ self[self.position_column] = self.class.maximum(:position, :conditions => (self.class.position_scope.blank? ? nil : eval(self.class.position_scope))).to_i + 1
48
+ end
49
+
50
+ end
51
+
52
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "positioned/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "positioned"
7
+ s.version = Positioned::VERSION
8
+ s.authors = ["Arend Miller", "Neal White"]
9
+ s.email = ["arend@cohesive.cc", "neal@cohesive.cc"]
10
+ s.homepage = "http://www.cohesive.cc"
11
+ s.summary = %q{}
12
+ s.description = %q{}
13
+
14
+ s.rubyforge_project = "positioned"
15
+
16
+ s.add_dependency "rails", "~> 3.0.1"
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.require_paths = ["lib"]
20
+ s.has_rdoc = false
21
+ s.licenses = ['MIT']
22
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: positioned
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Arend Miller
9
+ - Neal White
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2011-08-24 00:00:00.000000000 -05:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rails
18
+ requirement: &2161152680 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 3.0.1
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *2161152680
27
+ description: ''
28
+ email:
29
+ - arend@cohesive.cc
30
+ - neal@cohesive.cc
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - Gemfile
36
+ - LICENSE
37
+ - lib/positioned.rb
38
+ - lib/positioned/railtie.rb
39
+ - lib/positioned/version.rb
40
+ - positioned.gemspec
41
+ has_rdoc: true
42
+ homepage: http://www.cohesive.cc
43
+ licenses:
44
+ - MIT
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project: positioned
63
+ rubygems_version: 1.6.2
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: ''
67
+ test_files: []