blazy 0.1.2 → 0.1.3

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.
@@ -1,8 +1,8 @@
1
1
  == Description
2
2
 
3
- Blazy(be lazy) is a fluent extension to active record models to reduce number of key strokes in script/console.
3
+ Blazy(be lazy) is a fluent extension to active record models to reduce number of key strokes in rails console.
4
4
 
5
- Currently works with rails 2.2.x and 2.3.x
5
+ For rails 2.x refer to v0.1.2[https://github.com/endeepak/blazy/tree/v0.1.2]
6
6
 
7
7
  == Install
8
8
 
@@ -10,15 +10,19 @@ Currently works with rails 2.2.x and 2.3.x
10
10
 
11
11
  == Usage
12
12
 
13
- Go to script/console in your rails project and type
13
+ Add dependency in gem file
14
14
 
15
- require 'blazy'
15
+ gem 'blazy', :group => :development
16
+
17
+ Go to rails console in your rails project and type
18
+
19
+ Blazy.init
16
20
 
17
21
  you are ready to go!!
18
22
 
19
23
  == How does it help me?
20
24
 
21
- Most of the operations we do in script/console while debugging a problem or looking for model values in database take a lot of key strokes. Blazy provides methods, aliases and a fluent interface to reduce the number of keystrokes to bare minimal.
25
+ Most of the operations we do in rails console while debugging a problem or looking for model values in database take a lot of key strokes. Blazy provides methods, aliases and a fluent interface to reduce the number of keystrokes to bare minimal.
22
26
 
23
27
  == Examples
24
28
  Lets say you have a active record model called Project.
@@ -36,20 +40,11 @@ When you want to see some subset of data
36
40
 
37
41
  Scopes generated for each column
38
42
 
39
- Project.all(:conditions => {:name => 'blazy' }) --> Project.with_name('blazy') # you get autocomplete for this
40
-
41
- And its fluency using named scope (more like rails 3 way)
42
-
43
- Project.all(:conditions =>....) --> Project.where(..) or Project.with()
44
- Project.all(:limit => 10) --> Project.limit(10)
45
- Project.all(:order => 'name DESC') --> Project.order('name DESC')
46
- Project.all(:select => 'name') --> Project.select('name')
47
- Project.all(:conditions => ["name like '%lazy'"]) --> Project.where("name like '%lazy'") #can also use 'with' instead of 'where'
48
-
49
- And the power comes by chaining them
43
+ Project.where(:name => 'blazy') --> Project.with_name('blazy') # you get autocomplete for this
50
44
 
51
- 10.projects.with('priority < 2').order(:priority)
45
+ And chaining them
52
46
 
47
+ 10.projects.where('priority < 2').order(:priority)
53
48
  Project.with_priority(1).limit 10
54
49
 
55
50
  Lastly and actually the least some aliases. These are useful at the end of scope to inspect a model
data/Rakefile CHANGED
@@ -1,21 +1,21 @@
1
1
  require "rubygems"
2
2
  require "rake/gempackagetask"
3
3
  require "rake/rdoctask"
4
- require "spec"
5
- require "spec/rake/spectask"
4
+ require "rspec"
5
+ require "rspec/core/rake_task"
6
6
 
7
- Spec::Rake::SpecTask.new do |t|
8
- t.spec_opts = %w(--format specdoc --colour)
9
- t.libs = ["spec"]
7
+ RSpec::Core::RakeTask.new do |t|
8
+ t.rspec_opts = %w(--format documentation --color)
9
+ t.pattern = 'spec/**/*_spec.rb'
10
10
  end
11
11
 
12
12
  task :default => ["spec"]
13
13
 
14
14
  spec = Gem::Specification.new do |s|
15
15
  s.name = "blazy"
16
- s.version = "0.1.2"
16
+ s.version = "0.1.3"
17
17
  s.summary = "Provides fluent extensions and aliases to active record models"
18
- s.description = "Blazy(be lazy) is a fluent extension to active record models to reduce number of key strokes in script/console"
18
+ s.description = "Blazy(be lazy) is a fluent extension to active record models to reduce number of key strokes in rails console"
19
19
  s.author = "Deepak N"
20
20
  s.email = "endeep123@gmail.com"
21
21
  s.homepage = "http://github.com/endeepak/blazy"
@@ -24,10 +24,10 @@ spec = Gem::Specification.new do |s|
24
24
  s.rdoc_options = %w(--main README.rdoc)
25
25
  s.files = %w(Rakefile README.rdoc) + Dir.glob("{spec,lib/**/*}")
26
26
  s.require_paths = ["lib"]
27
- s.add_development_dependency('rspec', '= 1.3.0')
28
- s.add_development_dependency('activerecord', '= 2.3.5')
29
- s.add_development_dependency('active_support', '= 2.3.5')
30
- s.add_development_dependency('factory_girl', '= 1.2.4')
27
+ s.add_development_dependency('rspec', '= 2.1.0')
28
+ s.add_development_dependency('activerecord', '= 3.0.1')
29
+ s.add_development_dependency('active_support', '= 3.0.1')
30
+ s.add_development_dependency('factory_girl', '= 1.3.2')
31
31
  end
32
32
 
33
33
  Rake::GemPackageTask.new(spec) do |pkg|
@@ -61,15 +61,4 @@ end
61
61
  desc 'Clear out RDoc and generated packages'
62
62
  task :clean => [:clobber_rdoc, :clobber_package] do
63
63
  rm "#{spec.name}.gemspec"
64
- end
65
-
66
- namespace :db do
67
- namespace :mysql do
68
- desc 'Recreates test database in mysql server'
69
- task :recreate do
70
- `mysql -uroot -e "drop database if exists blazy_test"`
71
- `mysql -uroot -e "create database if not exists blazy_test"`
72
- `mysql -uroot -D blazy_test -e "show tables"`
73
- end
74
- end
75
- end
64
+ end
@@ -4,6 +4,10 @@ require 'active_support/inflector'
4
4
 
5
5
  require 'extensions/object'
6
6
  require 'extensions/active_record'
7
+ require 'extensions/rails'
7
8
 
8
- #HACKTAG:: Load all model from rails app model instead of lazy load - Testing this?
9
- Dir.glob(File.join(RAILS_ROOT,'app','models','**','*.rb')).each { |file| require_dependency file } if defined?(RAILS_ROOT)
9
+ module Blazy
10
+ def self.init
11
+ Rails.load_all_models
12
+ end
13
+ end
@@ -1,18 +1,12 @@
1
1
  class ActiveRecord::Base
2
- named_scope :with, lambda { |conditions| {:conditions => conditions } }
3
- named_scope :limit, lambda { |limit| {:limit => limit} }
4
- named_scope :order, lambda { |order| {:order => order} }
5
- named_scope :select, lambda { |*columns| {:select => columns} }
6
-
7
2
  class << self
8
- {:where => :with, :- => :find, :[] => :find, :f => :first, :a => :all, :l => :last}.each do |new_name, method|
3
+ {:- => :find, :[] => :find, :f => :first, :a => :all, :l => :last}.each do |new_name, method|
9
4
  eval "alias #{new_name} #{method}"
10
5
  end
11
6
  end
12
7
  end
13
8
 
14
9
  Dir.glob(File.join(File.dirname(__FILE__),'active_record','*.rb')).each { |file| require file }
15
- ActiveRecord::Base.send(:include, Blazy::Extensions::ActiveRecord::ScopeMerge)
16
10
  ActiveRecord::Base.send(:include, Blazy::Extensions::ActiveRecord::Object)
17
11
  ActiveRecord::Base.send(:include, Blazy::Extensions::ActiveRecord::Fixnum)
18
12
  ActiveRecord::Base.send(:include, Blazy::Extensions::ActiveRecord::ColumnScope)
@@ -4,7 +4,7 @@ module Blazy
4
4
  module ColumnScope
5
5
  def self.included(klass)
6
6
  klass.extend ClassMethods
7
- klass.send(:subclasses).each {|subclass| subclass.add_column_scope unless subclass.abstract_class?}
7
+ klass.send(:descendants).each {|subclass| subclass.add_column_scope unless subclass.abstract_class?}
8
8
  end
9
9
 
10
10
  module ClassMethods
@@ -15,7 +15,7 @@ module Blazy
15
15
 
16
16
  def add_column_scope
17
17
  self.columns.each do |column|
18
- self.named_scope "with_#{column.name}", lambda { |*params| {:conditions => { column.name => params } } }
18
+ self.scope "with_#{column.name}", lambda { |*params| {:conditions => { column.name => params } } }
19
19
  end
20
20
  rescue ::ActiveRecord::ActiveRecordError => e
21
21
  puts "Failed to add column scope for #{self.name} : #{e.message}"
@@ -4,7 +4,7 @@ module Blazy
4
4
  module Fixnum
5
5
  def self.included(klass)
6
6
  klass.extend ClassMethods
7
- klass.send(:subclasses).each {|subclass| subclass.add_extension_to_fixnum}
7
+ klass.send(:descendants).each {|subclass| subclass.add_extension_to_fixnum}
8
8
  end
9
9
 
10
10
  module ClassMethods
@@ -4,7 +4,7 @@ module Blazy
4
4
  module Object
5
5
  def self.included(klass)
6
6
  klass.extend ClassMethods
7
- klass.send(:subclasses).each {|subclass| subclass.add_extension_to_object}
7
+ klass.send(:descendants).each {|subclass| subclass.add_extension_to_object}
8
8
  end
9
9
 
10
10
  module ClassMethods
@@ -0,0 +1,12 @@
1
+ module Rails
2
+ #HACKTAG:: Load all model from rails app model instead of lazy load - Testing this?
3
+ def self.load_all_models
4
+ return false unless Rails.root
5
+ load_all('app','models','**','*.rb') and return true
6
+ end
7
+
8
+ private
9
+ def self.load_all(*paths)
10
+ Dir.glob(File.join(self.root,*paths)).each { |file| require_dependency file }
11
+ end
12
+ end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blazy
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 1
9
- - 2
10
- version: 0.1.2
8
+ - 3
9
+ version: 0.1.3
11
10
  platform: ruby
12
11
  authors:
13
12
  - Deepak N
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-10-11 00:00:00 +05:30
17
+ date: 2010-11-22 00:00:00 +05:30
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -26,12 +25,11 @@ dependencies:
26
25
  requirements:
27
26
  - - "="
28
27
  - !ruby/object:Gem::Version
29
- hash: 27
30
28
  segments:
29
+ - 2
31
30
  - 1
32
- - 3
33
31
  - 0
34
- version: 1.3.0
32
+ version: 2.1.0
35
33
  type: :development
36
34
  version_requirements: *id001
37
35
  - !ruby/object:Gem::Dependency
@@ -42,12 +40,11 @@ dependencies:
42
40
  requirements:
43
41
  - - "="
44
42
  - !ruby/object:Gem::Version
45
- hash: 9
46
43
  segments:
47
- - 2
48
44
  - 3
49
- - 5
50
- version: 2.3.5
45
+ - 0
46
+ - 1
47
+ version: 3.0.1
51
48
  type: :development
52
49
  version_requirements: *id002
53
50
  - !ruby/object:Gem::Dependency
@@ -58,12 +55,11 @@ dependencies:
58
55
  requirements:
59
56
  - - "="
60
57
  - !ruby/object:Gem::Version
61
- hash: 9
62
58
  segments:
63
- - 2
64
59
  - 3
65
- - 5
66
- version: 2.3.5
60
+ - 0
61
+ - 1
62
+ version: 3.0.1
67
63
  type: :development
68
64
  version_requirements: *id003
69
65
  - !ruby/object:Gem::Dependency
@@ -74,15 +70,14 @@ dependencies:
74
70
  requirements:
75
71
  - - "="
76
72
  - !ruby/object:Gem::Version
77
- hash: 23
78
73
  segments:
79
74
  - 1
75
+ - 3
80
76
  - 2
81
- - 4
82
- version: 1.2.4
77
+ version: 1.3.2
83
78
  type: :development
84
79
  version_requirements: *id004
85
- description: Blazy(be lazy) is a fluent extension to active record models to reduce number of key strokes in script/console
80
+ description: Blazy(be lazy) is a fluent extension to active record models to reduce number of key strokes in rails console
86
81
  email: endeep123@gmail.com
87
82
  executables: []
88
83
 
@@ -97,10 +92,10 @@ files:
97
92
  - lib/extensions/active_record/column_scope.rb
98
93
  - lib/extensions/active_record/fixnum.rb
99
94
  - lib/extensions/active_record/object.rb
100
- - lib/extensions/active_record/scope_merge.rb
101
95
  - lib/extensions/active_record.rb
102
96
  - lib/extensions/object/name.rb
103
97
  - lib/extensions/object.rb
98
+ - lib/extensions/rails.rb
104
99
  has_rdoc: true
105
100
  homepage: http://github.com/endeepak/blazy
106
101
  licenses: []
@@ -116,7 +111,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
111
  requirements:
117
112
  - - ">="
118
113
  - !ruby/object:Gem::Version
119
- hash: 3
120
114
  segments:
121
115
  - 0
122
116
  version: "0"
@@ -125,7 +119,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
119
  requirements:
126
120
  - - ">="
127
121
  - !ruby/object:Gem::Version
128
- hash: 3
129
122
  segments:
130
123
  - 0
131
124
  version: "0"
@@ -1,11 +0,0 @@
1
- module Blazy
2
- module Extensions
3
- module ActiveRecord
4
- module ScopeMerge
5
- def self.included(klass)
6
- klass.send(:subclasses).each {|subclass| subclass.scopes.reverse_merge!(klass.scopes) }
7
- end
8
- end
9
- end
10
- end
11
- end