blazy 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +41 -0
- data/Rakefile +64 -0
- data/lib/blazy.rb +8 -0
- data/lib/extensions/active_model.rb +15 -0
- data/lib/extensions/active_record.rb +3 -0
- data/lib/extensions/active_record/fixnum.rb +35 -0
- metadata +128 -0
data/README.rdoc
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
== Description
|
2
|
+
|
3
|
+
Blazy read as be_lazy is a handy extension to active record models meant to be used in script/console
|
4
|
+
|
5
|
+
== Install
|
6
|
+
|
7
|
+
Install the gem with:
|
8
|
+
|
9
|
+
sudo gem install blazy #Note: If you are using rvm to manage ruby versions don't use sudo
|
10
|
+
|
11
|
+
== Usage
|
12
|
+
|
13
|
+
Go to script/console in your rails project and type
|
14
|
+
|
15
|
+
require 'blazy'
|
16
|
+
|
17
|
+
you are ready to go!!
|
18
|
+
|
19
|
+
== Examples
|
20
|
+
|
21
|
+
If you have a model Project.
|
22
|
+
|
23
|
+
1.project or 2.projects to list projects
|
24
|
+
|
25
|
+
Project-11 to get project with id 11
|
26
|
+
|
27
|
+
== Work in progress
|
28
|
+
|
29
|
+
Searching a project as
|
30
|
+
|
31
|
+
Project.with_name('blazy') or 5.projects.with_name_like('%zy')
|
32
|
+
|
33
|
+
Chaining
|
34
|
+
|
35
|
+
5.projects.with_priority(3..5).not_completed
|
36
|
+
|
37
|
+
== Other useful gems in script/console
|
38
|
+
|
39
|
+
Wirble
|
40
|
+
|
41
|
+
Hirb
|
data/Rakefile
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "rake/gempackagetask"
|
3
|
+
require "rake/rdoctask"
|
4
|
+
require "spec"
|
5
|
+
require "spec/rake/spectask"
|
6
|
+
|
7
|
+
Spec::Rake::SpecTask.new do |t|
|
8
|
+
t.spec_opts = %w(--format specdoc --colour)
|
9
|
+
t.libs = ["spec"]
|
10
|
+
end
|
11
|
+
|
12
|
+
task :default => ["spec"]
|
13
|
+
|
14
|
+
spec = Gem::Specification.new do |s|
|
15
|
+
s.name = "blazy"
|
16
|
+
s.version = "0.1.1"
|
17
|
+
s.summary = "Provides fluent extension to active record models"
|
18
|
+
s.description = "Blazy read as be_lazy is a fluent extension to active record models and meant only to be used in script/console"
|
19
|
+
s.author = "Deepak N"
|
20
|
+
s.email = "endeep123@gmail.com"
|
21
|
+
s.homepage = "http://github.com/endeepak/blazy"
|
22
|
+
s.has_rdoc = true
|
23
|
+
s.extra_rdoc_files = %w(README.rdoc)
|
24
|
+
s.rdoc_options = %w(--main README.rdoc)
|
25
|
+
s.files = %w(Rakefile README.rdoc) + Dir.glob("{spec,lib/**/*}")
|
26
|
+
s.require_paths = ["lib"]
|
27
|
+
s.add_development_dependency('rspec')
|
28
|
+
s.add_development_dependency('activerecord')
|
29
|
+
s.add_development_dependency('active_support')
|
30
|
+
s.add_development_dependency('factory_girl')
|
31
|
+
end
|
32
|
+
|
33
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
34
|
+
pkg.gem_spec = spec
|
35
|
+
end
|
36
|
+
|
37
|
+
desc "Build the gemspec file #{spec.name}.gemspec"
|
38
|
+
task :gemspec do
|
39
|
+
file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
|
40
|
+
File.open(file, "w") {|f| f << spec.to_ruby }
|
41
|
+
end
|
42
|
+
|
43
|
+
desc "Install the gem locally"
|
44
|
+
task :install => :gem do
|
45
|
+
sh %{gem install pkg/#{spec.name}-#{spec.version}}
|
46
|
+
end
|
47
|
+
|
48
|
+
desc "Uninstall the gem"
|
49
|
+
task :uninstall do
|
50
|
+
sh %{gem uninstall #{spec.name}}
|
51
|
+
end
|
52
|
+
|
53
|
+
task :package => :gemspec
|
54
|
+
|
55
|
+
Rake::RDocTask.new do |rd|
|
56
|
+
rd.main = "README.rdoc"
|
57
|
+
rd.rdoc_files.include("README.rdoc", "lib/**/*.rb")
|
58
|
+
rd.rdoc_dir = "rdoc"
|
59
|
+
end
|
60
|
+
|
61
|
+
desc 'Clear out RDoc and generated packages'
|
62
|
+
task :clean => [:clobber_rdoc, :clobber_package] do
|
63
|
+
rm "#{spec.name}.gemspec"
|
64
|
+
end
|
data/lib/blazy.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'active_record'
|
3
|
+
require 'active_support/inflector'
|
4
|
+
|
5
|
+
require 'extensions/active_model'
|
6
|
+
require 'extensions/active_record'
|
7
|
+
|
8
|
+
Dir.glob(File.join(RAILS_ROOT,'app','models','**','*.rb')).each { |file| require_dependency file } if defined?(RAILS_ROOT)
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Blazy
|
2
|
+
module Extensions
|
3
|
+
module ActiveRecord
|
4
|
+
module Fixnum
|
5
|
+
def self.included(klass)
|
6
|
+
klass.extend ClassMethods
|
7
|
+
klass.send(:subclasses).each {|subclass| subclass.add_extension_to_fixnum}
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def inherited(klass)
|
12
|
+
klass.add_extension_to_fixnum
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
16
|
+
def add_extension_to_fixnum
|
17
|
+
underscored_model_name = self.name.demodulize.underscore
|
18
|
+
pluralized_underscored_model_name = underscored_model_name.pluralize
|
19
|
+
definition = <<-METHOD_DEFINITION
|
20
|
+
class ::Fixnum
|
21
|
+
def #{underscored_model_name}
|
22
|
+
record_to_find = self==1 ? :first : :all
|
23
|
+
#{self}.find(record_to_find, :limit => self)
|
24
|
+
end
|
25
|
+
alias #{pluralized_underscored_model_name} #{underscored_model_name}
|
26
|
+
end
|
27
|
+
METHOD_DEFINITION
|
28
|
+
eval(definition)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: blazy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Deepak N
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-10-04 00:00:00 +05:30
|
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: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: activerecord
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: active_support
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
type: :development
|
62
|
+
version_requirements: *id003
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: factory_girl
|
65
|
+
prerelease: false
|
66
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
type: :development
|
76
|
+
version_requirements: *id004
|
77
|
+
description: Blazy read as be_lazy is a fluent extension to active record models and meant only to be used in script/console
|
78
|
+
email: endeep123@gmail.com
|
79
|
+
executables: []
|
80
|
+
|
81
|
+
extensions: []
|
82
|
+
|
83
|
+
extra_rdoc_files:
|
84
|
+
- README.rdoc
|
85
|
+
files:
|
86
|
+
- Rakefile
|
87
|
+
- README.rdoc
|
88
|
+
- lib/blazy.rb
|
89
|
+
- lib/extensions/active_model.rb
|
90
|
+
- lib/extensions/active_record/fixnum.rb
|
91
|
+
- lib/extensions/active_record.rb
|
92
|
+
has_rdoc: true
|
93
|
+
homepage: http://github.com/endeepak/blazy
|
94
|
+
licenses: []
|
95
|
+
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options:
|
98
|
+
- --main
|
99
|
+
- README.rdoc
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
hash: 3
|
108
|
+
segments:
|
109
|
+
- 0
|
110
|
+
version: "0"
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
hash: 3
|
117
|
+
segments:
|
118
|
+
- 0
|
119
|
+
version: "0"
|
120
|
+
requirements: []
|
121
|
+
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 1.3.7
|
124
|
+
signing_key:
|
125
|
+
specification_version: 3
|
126
|
+
summary: Provides fluent extension to active record models
|
127
|
+
test_files: []
|
128
|
+
|