justools 1.2.4 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,8 @@
1
+ == 1.3.0
2
+
3
+ * Removing lots of methods no longer needed after ActiveSupport and Ruby 1.9+
4
+ * Reorganizing directory structure
5
+
1
6
  == 1.2.2
2
7
 
3
8
  * Moving constant for regular expression to array/args_and_opts to allow each extension to be indepedently required
@@ -10,23 +10,9 @@ Ruby-level extensions, utilities, convenience methods that I've found I'm consta
10
10
 
11
11
  === Object
12
12
 
13
- ==== Object#as
13
+ ==== Object#aka
14
14
 
15
- [:donkey, { :class => 'list-item' }].as { |arg, opts| link_to(arg, opts) }
16
-
17
- ==== Object#is_included_in? (deprecated by ActiveSupport's newest Object#in?)
18
-
19
- User.find(1).class.is_included_in?(User, Article, Authentication)
20
-
21
- or alternatively:
22
-
23
- @user.is_one_kind_of?(User, Article, Authentication)
24
-
25
- which has the same effect as:
26
-
27
- @user.is_one_kind_of?([User, Article, Authentication])
28
-
29
- by virtue of:
15
+ [:donkey, { :class => 'list-item' }].aka { |arg, opts| link_to(arg, opts) }
30
16
 
31
17
  === Array
32
18
 
@@ -132,4 +118,5 @@ http://github.com/caleon/justools/contributors
132
118
 
133
119
  == License
134
120
 
135
- MIT License. Copyright 2012 caleon.
121
+ MIT License. Copyright 2013 caleon.
122
+
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.4
1
+ 1.3.0
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "justools"
8
- s.version = "1.2.4"
8
+ s.version = "1.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["caleon"]
@@ -27,19 +27,18 @@ Gem::Specification.new do |s|
27
27
  "VERSION",
28
28
  "justools.gemspec",
29
29
  "lib/justools.rb",
30
- "lib/justools/core_ext.rb",
30
+ "lib/justools/all.rb",
31
31
  "lib/justools/core_ext/array.rb",
32
32
  "lib/justools/core_ext/array/args_and_opts.rb",
33
33
  "lib/justools/core_ext/array/filters.rb",
34
34
  "lib/justools/core_ext/array/flatten_splat.rb",
35
35
  "lib/justools/core_ext/array/inquiry.rb",
36
36
  "lib/justools/core_ext/array/merge_options.rb",
37
- "lib/justools/core_ext/class.rb",
38
37
  "lib/justools/core_ext/enumerable.rb",
39
38
  "lib/justools/core_ext/hash.rb",
40
39
  "lib/justools/core_ext/object.rb",
41
40
  "lib/justools/core_ext/set.rb",
42
- "lib/tasks/core_utilities_tasks.rake",
41
+ "lib/tasks/justools_tasks.rake",
43
42
  "spec/justools_spec.rb",
44
43
  "spec/spec_helper.rb"
45
44
  ]
@@ -1,4 +1,3 @@
1
- # require 'justools/core_ext'
2
-
3
1
  module Justools
2
+
4
3
  end
@@ -1,4 +1,3 @@
1
- # require 'justools/core_ext/class'
2
1
  require 'justools/core_ext/object'
3
2
  require 'justools/core_ext/enumerable'
4
3
  require 'justools/core_ext/set'
@@ -1,6 +1,4 @@
1
1
  require 'set'
2
- require 'justools/core_ext/object'
3
- require 'justools/core_ext/set'
4
2
  require 'justools/core_ext/array/flatten_splat'
5
3
 
6
4
  class Array
@@ -12,31 +10,12 @@ class Array
12
10
  def rearranged?(*other_ary)
13
11
  Set.new(self) == Set.new(other_ary.flatten_splat)
14
12
  end
15
- alias_method :rearranges?, :rearranged?
16
13
 
17
- def subset_of?(other_ary)
14
+ def subset?(other_ary)
18
15
  Set.new(self).subset?(Set.new(other_ary))
19
16
  end
20
- alias_method :subset?, :subset_of?
21
17
 
22
- def is_included_in?(other_ary)
18
+ def in?(other_ary)
23
19
  super || subset?(other_ary)
24
20
  end
25
- alias_method :in?, :is_included_in?
26
-
27
- # Careful with this. This means 4 out of 5 elements can be the same but if not
28
- # all of this self Array object are a part of other_ary, this returns true, as
29
- # in "Yes, depite having 4 out of 5 in other_ary, I am excluded from the
30
- # other_ary."
31
- def out_of?(other_ary)
32
- super || not_subset?(other_ary)
33
- end
34
- alias_method :is_excluded_from?, :out_of?
35
-
36
- alias_method :include_one?, :include?
37
- def include_all?(*other_ary)
38
- other_ary.flatten_splat!
39
- include_one(other_ary) || superset?(other_ary)
40
- end
41
- # alias_method :include?, :include_all?
42
21
  end
@@ -4,89 +4,14 @@ class Object
4
4
 
5
5
  # === Examples
6
6
  #
7
- # { :a=>1, .., :z=>26 }.as { |h| h.each { |k, v| h[k] = v + h[26 - v] } }
7
+ # { :a=>1, .., :z=>26 }.aka { |h| h.each { |k, v| h[k] = v + h[26 - v] } }
8
8
  #
9
- # User.find(15).stories.joins(:tasks).as { |s| [s.class.to_s, s.count] }.
10
- # as { |klass_name, count| "#{count} stories in #{klass_name}" }
9
+ # User.find(15).stories.joins(:tasks).aka { |s| [s.class.to_s, s.count] }.
10
+ # aka { |klass_name, count| "#{count} stories in #{klass_name}" }
11
11
  #
12
12
  # [15, { :includes => { :stories => :tasks } }, 56, 78, 102].
13
- # as { |id, opts, *ns| ns.each { |n| puts n }; User.find(id, opts) }
14
- def as(&block)
13
+ # aka { |id, opts, *ns| ns.each { |n| puts n }; User.find(id, opts) }
14
+ def aka(&block)
15
15
  yield self
16
16
  end
17
-
18
- # === Examples
19
- #
20
- # user = User.find_by_id(10).or_else { |res| raise "Got back #{res}" }
21
- def or_else(&block)
22
- self || yield(self)
23
- end
24
-
25
- # === Examples
26
- #
27
- # authorization = User.find_by_id(10).and_also { |u| u.authorization }
28
- def and_also(&block)
29
- self && yield(self)
30
- end
31
-
32
- # unless Object.method_defined?(:in?)
33
- # Copy of Object#in? from Rails 3.2.1 which also allows list.
34
- #
35
- # === Parameters
36
- #
37
- # * +args+ - Array or a list of its contents.
38
- def in?(*args)
39
- if args.length > 1
40
- args.include? self
41
- else
42
- another_object = args.first
43
- if another_object.respond_to? :include?
44
- another_object.include?(self)
45
- else
46
- raise ArgumentError.new("The single parameter passed to #in? must respond to #include?")
47
- end
48
- end
49
- end
50
- # end
51
- # def is_included_in?(*others) #d deprecated
52
- # others.flatten_splat.include?(self)
53
- # end
54
- alias_method :is_included_in?, :in?
55
-
56
- def out_of?(*others)
57
- others.flatten_splat.exclude?(self)
58
- end
59
- alias_method :is_excluded_from?, :out_of?
60
-
61
- # Similar to is_a? or kind_of? but with an array of possible classes.
62
- # Returns the matching class or a nil.
63
- #
64
- # === Parameters
65
- #
66
- # * +klasses+ - List of Class constants, or an Array of Class constants.
67
- #
68
- # === Examples
69
- #
70
- # rec_or_num.one_kind_of?(User, Admin).or_else { User.find(rec_or_num) }
71
- def one_kind_of?(*klasses)
72
- klasses.flatten_splat.detect { |klass| self.kind_of?(klass) }
73
- end
74
- alias_method :is_one_kind_of?, :one_kind_of?
75
-
76
- # Similar to is_a? or kind_of? but with an array of possible classes.
77
- # Returns the matching class or a nil. Renamed here from is_one_kind_of?
78
- # because it uses the 'klass === self' which isn't necessarily equivalent to
79
- # 'self.is_a?(klass)'.
80
- #
81
- # === Parameters
82
- #
83
- # * +args+ - List of arguments.
84
- #
85
- # === Examples
86
- #
87
- # rec_or_num.one_of?(User, Admin).or_else { User.find(rec_or_num) }
88
- def one_of?(*args)
89
- args.flatten_splat.detect { |arg| arg === self}
90
- end
91
- alias_method :is_when?, :one_of?
92
17
  end
@@ -1,3 +1,5 @@
1
+ require 'set'
2
+
1
3
  class Set
2
4
  def not_subset?(set)
3
5
  set.is_a?(Set) or raise ArgumentError, "value must be a set"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: justools
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
4
+ version: 1.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -109,19 +109,18 @@ files:
109
109
  - VERSION
110
110
  - justools.gemspec
111
111
  - lib/justools.rb
112
- - lib/justools/core_ext.rb
112
+ - lib/justools/all.rb
113
113
  - lib/justools/core_ext/array.rb
114
114
  - lib/justools/core_ext/array/args_and_opts.rb
115
115
  - lib/justools/core_ext/array/filters.rb
116
116
  - lib/justools/core_ext/array/flatten_splat.rb
117
117
  - lib/justools/core_ext/array/inquiry.rb
118
118
  - lib/justools/core_ext/array/merge_options.rb
119
- - lib/justools/core_ext/class.rb
120
119
  - lib/justools/core_ext/enumerable.rb
121
120
  - lib/justools/core_ext/hash.rb
122
121
  - lib/justools/core_ext/object.rb
123
122
  - lib/justools/core_ext/set.rb
124
- - lib/tasks/core_utilities_tasks.rake
123
+ - lib/tasks/justools_tasks.rake
125
124
  - spec/justools_spec.rb
126
125
  - spec/spec_helper.rb
127
126
  homepage: http://github.com/caleon/justools
@@ -139,7 +138,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
139
138
  version: '0'
140
139
  segments:
141
140
  - 0
142
- hash: -73736662650008813
141
+ hash: -3606103884830383195
143
142
  required_rubygems_version: !ruby/object:Gem::Requirement
144
143
  none: false
145
144
  requirements:
@@ -1,41 +0,0 @@
1
- # Not enabling until fixed.
2
- require 'active_support/core_ext/class/attribute'
3
- require 'active_support/core_ext/module/aliasing'
4
-
5
- class Class
6
- # Purpose is to be able to define a default value for a class_attribute when
7
- # one isn't initially set.
8
- def class_attribute_with_default(*attrs)
9
- hash = attrs.last.is_a?(Hash) ? attrs.pop : {}
10
- my_default = hash.delete(:default)
11
- instance_writer = hash.blank? || hash[:instance_writer]
12
-
13
- attrs.each do |name|
14
- # By the way, FIXME: i think this should be broken because if i want to
15
- # use a string as a default, that will not be reflected.
16
- class_eval <<-RUBY, __FILE__, __LINE__ + 1
17
- def self.#{name}() #{my_default || 'nil'} end
18
- def self.#{name}?() !!#{name} end
19
-
20
- def self.#{name}=(val)
21
- singleton_class.class_eval do
22
- remove_possible_method(:#{name})
23
- define_method(:#{name}) { val }
24
- end
25
- val
26
- end
27
-
28
- def #{name}
29
- defined?(@#{name}) ? @#{name} : singleton_class.#{name}
30
- end
31
-
32
- def #{name}?
33
- !!#{name}
34
- end
35
- RUBY
36
-
37
- attr_writer name if instance_writer
38
- end
39
- end
40
- alias_method_chain :class_attribute, :default
41
- end