acts_as_extjs 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gemspec ADDED
@@ -0,0 +1,48 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = nil
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.date = %q{2010-07-23}
12
+ s.extra_rdoc_files = [
13
+ "README"
14
+ ]
15
+ s.files = [
16
+ "MIT-LICENSE",
17
+ "README",
18
+ "Rakefile",
19
+ "VERSION",
20
+ "acts_as_extjs.gemspec",
21
+ "init.rb",
22
+ "install.rb",
23
+ "lib/acts_as_extjs.rb",
24
+ "lib/tasks/acts_as_extjs.rake",
25
+ "test/acts_as_extjs_test.rb",
26
+ "test/test_helper.rb",
27
+ "uninstall.rb"
28
+ ]
29
+ s.rdoc_options = ["--charset=UTF-8"]
30
+ s.require_paths = ["lib"]
31
+ s.rubygems_version = %q{1.3.7}
32
+ s.summary = nil
33
+ s.test_files = [
34
+ "test/acts_as_extjs_test.rb",
35
+ "test/test_helper.rb"
36
+ ]
37
+
38
+ if s.respond_to? :specification_version then
39
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
40
+ s.specification_version = 3
41
+
42
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
43
+ else
44
+ end
45
+ else
46
+ end
47
+ end
48
+
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ # rcov generated
2
+ coverage
3
+
4
+ # rdoc generated
5
+ rdoc
6
+
7
+ # yard generated
8
+ doc
9
+ .yardoc
10
+
11
+ # jeweler generated
12
+ pkg
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Marco Scholl
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.
data/README ADDED
@@ -0,0 +1,15 @@
1
+ ActsAsExtjs
2
+ ===========
3
+
4
+ ActiveRecord Helper for Extjs
5
+
6
+
7
+ Example
8
+ =======
9
+
10
+ class Model < ActiveRecord::Base
11
+ acts_as_extjs
12
+ end
13
+
14
+
15
+ Copyright (c) 2010 Marco Scholl, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,58 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "acts_as_extjs"
8
+ gem.summary = %Q{ActiveRecord Helper for Extjs}
9
+ gem.description = %Q{ActiveRecord Helper for Extjs}
10
+ gem.email = "develop@marco-scholl.de"
11
+ gem.homepage = "http://github.com/traxanos/acts_as_extjs"
12
+ gem.authors = ["Marco Scholl"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'spec/rake/spectask'
22
+ Spec::Rake::SpecTask.new(:spec) do |spec|
23
+ spec.libs << 'lib' << 'spec'
24
+ spec.spec_files = FileList['spec/**/*_spec.rb']
25
+ end
26
+
27
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
28
+ spec.libs << 'lib' << 'spec'
29
+ spec.pattern = 'spec/**/*_spec.rb'
30
+ spec.rcov = true
31
+ end
32
+
33
+ task :spec => :check_dependencies
34
+
35
+ begin
36
+ require 'reek/adapters/rake_task'
37
+ Reek::RakeTask.new do |t|
38
+ t.fail_on_error = true
39
+ t.verbose = false
40
+ t.source_files = 'lib/**/*.rb'
41
+ end
42
+ rescue LoadError
43
+ task :reek do
44
+ abort "Reek is not available. In order to run reek, you must: sudo gem install reek"
45
+ end
46
+ end
47
+
48
+ task :default => :spec
49
+
50
+ require 'rake/rdoctask'
51
+ Rake::RDocTask.new do |rdoc|
52
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
53
+
54
+ rdoc.rdoc_dir = 'rdoc'
55
+ rdoc.title = "acts_as_extjs #{version}"
56
+ rdoc.rdoc_files.include('README*')
57
+ rdoc.rdoc_files.include('lib/**/*.rb')
58
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,55 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{acts_as_extjs}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Marco Scholl"]
12
+ s.date = %q{2010-07-23}
13
+ s.description = %q{ActiveRecord Helper for Extjs}
14
+ s.email = %q{develop@marco-scholl.de}
15
+ s.extra_rdoc_files = [
16
+ "README"
17
+ ]
18
+ s.files = [
19
+ ".gemspec",
20
+ ".gitignore",
21
+ "MIT-LICENSE",
22
+ "README",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "acts_as_extjs.gemspec",
26
+ "init.rb",
27
+ "lib/acts_as_extjs.rb",
28
+ "spec/acts_as_extjs_spec.rb",
29
+ "spec/spec.opts",
30
+ "spec/spec_helper.rb"
31
+ ]
32
+ s.homepage = %q{http://github.com/traxanos/acts_as_extjs}
33
+ s.rdoc_options = ["--charset=UTF-8"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = %q{1.3.7}
36
+ s.summary = %q{ActiveRecord Helper for Extjs}
37
+ s.test_files = [
38
+ "spec/acts_as_extjs_spec.rb",
39
+ "spec/spec_helper.rb"
40
+ ]
41
+
42
+ if s.respond_to? :specification_version then
43
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
48
+ else
49
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
50
+ end
51
+ else
52
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
53
+ end
54
+ end
55
+
data/init.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'acts_as_extjs'
2
+ ActiveRecord::Base.send(:include, Extjs::ActsAsExtjs)
@@ -0,0 +1,125 @@
1
+ module Extjs #:nodoc:
2
+ module ActsAsExtjs #:nodoc:
3
+
4
+ def self.included(base)
5
+ base.extend ClassMethods
6
+ end
7
+
8
+ module ClassMethods
9
+ def acts_as_extjs
10
+ named_scope :extjs
11
+ include Extjs::ActsAsExtjs::InstanceMethods
12
+ extend Extjs::ActsAsExtjs::SingletonMethods
13
+ end
14
+ end
15
+
16
+ module SingletonMethods
17
+ def extjs_result(*args)
18
+ options = args.extract_options!
19
+ fields = options.delete(:fields)
20
+ start = options.delete(:start).to_i
21
+ limit = options.delete(:limit).to_i
22
+
23
+ sort_mapping = options.delete(:sort_mapping)
24
+ sort_by = options.delete(:sort_by)
25
+ sort_dir = options.delete(:sort_dir)
26
+ group_by = options.delete(:group_by)
27
+ group_dir = options.delete(:group_dir)
28
+
29
+ unless sort_mapping.blank?
30
+ if not sort_by.blank? and sort_mapping.has_key?(sort_by.to_sym)
31
+ if sort_dir.to_s.downcase == "desc"
32
+ sort_dir = " DESC"
33
+ else
34
+ sort_dir = " ASC"
35
+ end
36
+ order = sort_mapping[sort_by.to_sym] + sort_dir
37
+ else
38
+ order = 'created_at DESC'
39
+ end
40
+
41
+
42
+ if not group_by.blank? and sort_mapping.has_key?(group_by.to_sym)
43
+ if group_dir.to_s.downcase == "desc"
44
+ group_dir = " DESC"
45
+ else
46
+ group_dir = " ASC"
47
+ end
48
+ order = sort_mapping[group_by.to_sym] + group_dir + ', ' + order
49
+ end
50
+
51
+ options[:order] = order if order
52
+ end
53
+
54
+ if limit.to_i > 0 or options[:per_page].to_i > 0
55
+ options[:per_page] = limit if limit > 0
56
+ options[:page] = (start > 0) ? (start/limit)+1 : 1
57
+ result = self.extjs.paginate options
58
+ total = result.total_entries
59
+ else
60
+ result = self.extjs.all options
61
+ total = result.size
62
+ end
63
+
64
+ rows = []
65
+ result.each do |result_row|
66
+ row = {}
67
+ fields.collect do |field|
68
+ if field[:mapping].blank?
69
+ if field[:custom].is_a? Proc
70
+ row[field[:name]] = field[:custom].call(result_row)
71
+ else
72
+ row[field[:name]] = result_row.send(field[:name])
73
+ end
74
+ if row[field].is_a? ActiveSupport::TimeWithZone or row[field[:name]].is_a? DateTime or row[field[:name]].is_a? Time
75
+ row[field[:name]] = row[field[:name]].strftime("%Y-%m-%d %H:%M:%S")
76
+ end
77
+ end
78
+ end
79
+ rows << row
80
+ end
81
+
82
+ return {
83
+ :total => total,
84
+ :data => rows,
85
+ :metaData => {
86
+ :root => :data,
87
+ :messageProperty => 'message',
88
+ :successProperty => 'success',
89
+ :fields => fields,
90
+ :idProperty => :id,
91
+ :totalProperty => :total,
92
+ }
93
+ }
94
+ end
95
+ end
96
+
97
+ module InstanceMethods
98
+ def extjs_error
99
+ error = self.errors.first
100
+ if error.nil?
101
+ nil
102
+ else
103
+ if error.last.at(0) == '^'
104
+ error.last.slice(1..-1)
105
+ else
106
+ "#{self.class.human_attribute_name(error.first)} #{error.last}"
107
+ end
108
+ end
109
+ end
110
+
111
+ def extjs_errors
112
+ hash = {}
113
+ self.errors.each do |error|
114
+ if error.last.at(0) == '^'
115
+ message = error.last.slice(1..-1)
116
+ else
117
+ message = "#{self.class.human_attribute_name(error.first)} #{error.last}"
118
+ end
119
+ hash["data[#{error.first}]"] = message
120
+ end
121
+ return hash
122
+ end
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "ActsAsExtjs" do
4
+ it "fails" do
5
+ #fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'acts_as_extjs'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: acts_as_extjs
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Marco Scholl
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-07-23 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 13
30
+ segments:
31
+ - 1
32
+ - 2
33
+ - 9
34
+ version: 1.2.9
35
+ type: :development
36
+ version_requirements: *id001
37
+ description: ActiveRecord Helper for Extjs
38
+ email: develop@marco-scholl.de
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files:
44
+ - README
45
+ files:
46
+ - .gemspec
47
+ - .gitignore
48
+ - MIT-LICENSE
49
+ - README
50
+ - Rakefile
51
+ - VERSION
52
+ - acts_as_extjs.gemspec
53
+ - init.rb
54
+ - lib/acts_as_extjs.rb
55
+ - spec/acts_as_extjs_spec.rb
56
+ - spec/spec.opts
57
+ - spec/spec_helper.rb
58
+ has_rdoc: true
59
+ homepage: http://github.com/traxanos/acts_as_extjs
60
+ licenses: []
61
+
62
+ post_install_message:
63
+ rdoc_options:
64
+ - --charset=UTF-8
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ hash: 3
82
+ segments:
83
+ - 0
84
+ version: "0"
85
+ requirements: []
86
+
87
+ rubyforge_project:
88
+ rubygems_version: 1.3.7
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: ActiveRecord Helper for Extjs
92
+ test_files:
93
+ - spec/acts_as_extjs_spec.rb
94
+ - spec/spec_helper.rb