flag_shih_tzu 0.3.12 → 0.3.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 90b55064f920798177d3ca8c7eaf24141d275266
4
- data.tar.gz: 4c56f730ebcd6de7721312f81809ecede06cbcd7
3
+ metadata.gz: a2714d0ae0f43d03bd6e24a3ac96ec0a5a2126ec
4
+ data.tar.gz: 5f31617f4cb4c1ef1e3ad3ccc3db9a813004bfa7
5
5
  SHA512:
6
- metadata.gz: 3b9a1d00be762409224b7cafd6244a93cf062ff721d218ea5c9b167ee6963cfa1a1a1ba8ce3b24ae71146df74e674771d58e9139b139eb4c822c7af0546f108b
7
- data.tar.gz: e5438b3889ca9d3caf04d18b54ecc26587190368978fa8cc51626b41c30596fa051a08c02a43a98aa3ce36d4a8938845d1e01a4dc87e3d651f5ecc5ad64fd2a6
6
+ metadata.gz: 4494baacf8d5733f126459e7880e5cb33e8465a59de8d709262da9734c447c49085d5b165c7bbfc468ec7479f9965371384b6a55d0f43ef9edb227783c1cafe1
7
+ data.tar.gz: bd3ef847e260134e8ed842fe6c176473f56538e677ec3396285babfba7d4c5213acf920a141667620c7351de8696316b84500503d29def67ec4c854475627ed2
data/.travis.yml CHANGED
@@ -1,8 +1,8 @@
1
1
  rvm:
2
- - 1.9.2
3
2
  - 1.9.3
4
3
  - 2.0.0
5
4
  - 2.1.2
5
+ - 2.2.1
6
6
  gemfile:
7
7
  - gemfiles/Gemfile.activerecord-2.3.x
8
8
  - gemfiles/Gemfile.activerecord-3.0.x
@@ -12,6 +12,22 @@ gemfile:
12
12
  - gemfiles/Gemfile.activerecord-4.1.x
13
13
  matrix:
14
14
  exclude:
15
+ - rvm: 2.2.1
16
+ gemfile: gemfiles/Gemfile.activerecord-2.3.x
17
+ - rvm: 2.2.1
18
+ gemfile: gemfiles/Gemfile.activerecord-3.0.x
19
+ - rvm: 2.2.1
20
+ gemfile: gemfiles/Gemfile.activerecord-3.1.x
21
+ - rvm: 2.2.1
22
+ gemfile: gemfiles/Gemfile.activerecord-3.2.x
23
+ - rvm: 2.2.1
24
+ gemfile: gemfiles/Gemfile.activerecord-4.0.x
25
+ - rvm: 2.1.2
26
+ gemfile: gemfiles/Gemfile.activerecord-2.3.x
27
+ - rvm: 2.1.2
28
+ gemfile: gemfiles/Gemfile.activerecord-3.0.x
29
+ - rvm: 2.1.2
30
+ gemfile: gemfiles/Gemfile.activerecord-3.1.x
15
31
  - rvm: 2.1.2
16
32
  gemfile: gemfiles/Gemfile.activerecord-2.3.x
17
33
  - rvm: 2.1.2
@@ -1,4 +1,18 @@
1
+ Version 0.3.13 - MAR.13.2015
2
+
3
+ * methods for use with form builders like simple_form by Peter Boling
4
+
5
+ - chained_flags_with_signature
6
+ - chained_#{colmn}_with_signature
7
+ - as_flag_collection
8
+ - as_#{colmn.singularize}_collection
9
+ - selected_flags=
10
+ - selected_#{colmn}= (already existed)
11
+ * Testing on Travis: added Ruby 2.2.1
12
+ * Testing on Travis: removed Ruby 1.9.2
13
+
1
14
  Version 0.3.12 - OCT.01.2014
15
+
2
16
  * Improve testing instructions in readme by Peter Boling
3
17
  * fix check_flag_column to return false after warn by Peter Boling
4
18
  * bash script for running complete test suite on Ruby 1.9.3 and Ruby 2.1.2 by Peter Boling
@@ -9,34 +23,41 @@ Version 0.3.12 - OCT.01.2014
9
23
  * Use Kernel#warn instead of puts by Peter Boling
10
24
 
11
25
  Version 0.3.11 - JUL.09.2014
26
+
12
27
  * Rename some ambigously-named methods mixed into AR::Base by jdelStrother
13
28
  * Add dynamic ".*_values_for" helpers by atipugin
14
29
 
15
30
  Version 0.3.10 - NOV.26.2013
31
+
16
32
  * Can run tests without coverage by specifying NOCOVER=true by Peter Boling
17
33
  * Improved test coverage by Peter Boling
18
34
  * Improved documentation by Peter Boling
19
35
  * Readme converted to Markdown by Peter Boling
20
36
 
21
37
  Version 0.3.9 - NOV.25.2013
38
+
22
39
  * Removed runtime dependency on active record and active support by Peter Boling
23
40
  * Fixed Coveralls Configuration by Peter Boling
24
41
  * Improved Readme by Peter Boling
25
42
 
26
43
  Version 0.3.8 - NOV.24.2013
44
+
27
45
  * Improved Readme / Documentation by Peter Boling
28
46
  * Added Badges by Peter Boling
29
47
  * Configured Coveralls by Peter Boling
30
48
  * Added Code Climate, Coveralls, Gemnasium, and Version Badges by Peter Boling
31
49
 
32
50
  Version 0.3.7 - OCT.25.2013
51
+
33
52
  * Change `sql_in_for_flag` to consider values from the range [0, 2 * max - 1] by Blake Thomson
34
53
 
35
54
  Version 0.3.6 - AUG.29.2013
55
+
36
56
  * Allow use with any gem manager by Peter Boling
37
57
  * No need to alter Ruby's load path by Peter Boling
38
58
 
39
59
  Version 0.3.5 - AUG.06.2013
60
+
40
61
  * Fix Travis Build & Add Rails 4 by Peter M. Goldstein
41
62
  * Implemented update_flag! by Peter Boling (see https://github.com/pboling/flag_shih_tzu/issues/27)
42
63
  - sets a flag on a record without triggering callbacks or validations
@@ -60,6 +81,7 @@ Version 0.3.4 - JUN.20.2013
60
81
  * Many more tests, including arity tests by Peter Boling
61
82
 
62
83
  Version 0.3.3 - JUN.20.2013
84
+
63
85
  - Does not exist.
64
86
 
65
87
  Version 0.3.2 - NOV.06.2012
data/README.md CHANGED
@@ -48,9 +48,9 @@ What is a ["Shih Tzu"](http://en.wikipedia.org/wiki/Shih_Tzu)?
48
48
  The gem is actively being tested with:
49
49
 
50
50
  * MySQL, PostgreSQL and SQLite3 databases
51
- * ActiveRecord versions 2.3.x, 3.0.x, 3.1.x, 3.2.x
52
- * Ruby 1.8.7, 1.9.2, 1.9.3, and 2.0.0 (see .travis.yml for the matrix)
53
-
51
+ * ActiveRecord versions 2.3.x, 3.0.x, 3.1.x, 3.2.x, 4.0.x, 4.1.x ;)
52
+ * Ruby 1.9.2, 1.9.3, 2.0.0, 2.1.2 (see .travis.yml for the matrix)
53
+ * Legacy Ruby 1.8.7 compatibility is in the [0.2.X branch](https://github.com/pboling/flag_shih_tzu/tree/0.2.X)
54
54
 
55
55
  ## Installation
56
56
 
data/lib/flag_shih_tzu.rb CHANGED
@@ -29,7 +29,6 @@ module FlagShihTzu
29
29
  :strict => false,
30
30
  :check_for_column => true
31
31
  }.update(opts)
32
- colmn = opts[:column].to_s
33
32
  if !is_valid_flag_column_name(opts[:column])
34
33
  warn "FlagShihTzu says: Please use a String to designate column names! I see you here: #{caller.first}"
35
34
  opts[:column] = opts[:column].to_s
@@ -61,7 +60,6 @@ module FlagShihTzu
61
60
  raise ArgumentError, "has_flags: flag name #{flag_name} already defined, please choose different name" if method_defined?(flag_name)
62
61
 
63
62
  flag_mapping[colmn][flag_name] = 1 << (flag_key - 1)
64
- #puts "Defined: #{flag_key} as #{flag_mapping[colmn][flag_name]}"
65
63
 
66
64
  class_eval <<-EVAL, __FILE__, __LINE__ + 1
67
65
  def #{flag_name}
@@ -144,9 +142,9 @@ module FlagShihTzu
144
142
  end
145
143
 
146
144
  # useful for a form builder
147
- def selected_#{colmn}=(selected_flags)
145
+ def selected_#{colmn}=(chosen_flags)
148
146
  unselect_all_flags('#{colmn}')
149
- selected_flags.each do |selected_flag|
147
+ chosen_flags.each do |selected_flag|
150
148
  enable_flag(selected_flag.to_sym, '#{colmn}') if selected_flag.present?
151
149
  end
152
150
  end
@@ -155,6 +153,14 @@ module FlagShihTzu
155
153
  not selected_#{colmn}.empty?
156
154
  end
157
155
 
156
+ def chained_#{colmn}_with_signature(*args)
157
+ chained_flags_with_signature('#{colmn}', *args)
158
+ end
159
+
160
+ def as_#{colmn.singularize}_collection(*args)
161
+ as_flag_collection('#{colmn}', *args)
162
+ end
163
+
158
164
  EVAL
159
165
  end
160
166
 
@@ -211,15 +217,15 @@ module FlagShihTzu
211
217
  raise NoSuchFlagException.new("determine_flag_colmn_for: Couldn't determine column for your flags!")
212
218
  end
213
219
 
214
- def chained_flags_with(*args)
220
+ def chained_flags_with(column = DEFAULT_COLUMN_NAME, *args)
215
221
  if (ActiveRecord::VERSION::MAJOR >= 3)
216
- where(chained_flags_condition(*args))
222
+ where(chained_flags_condition(column, *args))
217
223
  else
218
- all(:conditions => chained_flags_condition(*args))
224
+ all(:conditions => chained_flags_condition(column, *args))
219
225
  end
220
226
  end
221
227
 
222
- def chained_flags_condition(colmn, *args)
228
+ def chained_flags_condition(colmn = DEFAULT_COLUMN_NAME, *args)
223
229
  "(#{self.table_name}.#{colmn} in (#{chained_flags_values(colmn, *args).join(',')}))"
224
230
  end
225
231
 
@@ -385,6 +391,15 @@ module FlagShihTzu
385
391
  all_flags(colmn).map { |flag_name| self.send(flag_name) ? flag_name : nil }.compact
386
392
  end
387
393
 
394
+ # Useful for a form builder
395
+ # use selected_#{column}= for custom column names.
396
+ def selected_flags=(chosen_flags)
397
+ unselect_all_flags
398
+ chosen_flags.each do |selected_flag|
399
+ enable_flag(selected_flag.to_sym, DEFAULT_COLUMN_NAME) if selected_flag.present?
400
+ end
401
+ end
402
+
388
403
  def select_all_flags(colmn = DEFAULT_COLUMN_NAME)
389
404
  all_flags(colmn).each do |flag|
390
405
  enable_flag(flag, colmn)
@@ -420,8 +435,43 @@ module FlagShihTzu
420
435
  end
421
436
  end
422
437
 
438
+ # Use with chained_flags_with to find records with specific flags set to the same values as on this record.
439
+ # For a record that has sent_warm_up_email = true and the other flags false:
440
+ # user.chained_flags_with_signature
441
+ # => [:sent_warm_up_email, :not_follow_up_called, :not_sent_final_email, :not_scheduled_appointment]
442
+ # User.chained_flags_with('flags', *user.chained_flags_with_signature)
443
+ # => the set of Users that have the same flags set as user.
444
+ def chained_flags_with_signature(colmn = DEFAULT_COLUMN_NAME, *args)
445
+ flags_to_collect = args.empty? ? all_flags(colmn) : args
446
+ truthy_and_chosen = selected_flags(colmn).select {|x| flags_to_collect.include?(x) }
447
+ truthy_and_chosen.concat(
448
+ collect_flags(*flags_to_collect) do |memo, flag|
449
+ memo << "not_#{flag}".to_sym unless truthy_and_chosen.include?(flag)
450
+ end
451
+ )
452
+ end
453
+
454
+ # Use with a checkbox form builder, like simple_form's
455
+ # # selected_flags, used in the example below, is a method defined by flag_shih_tzu for bulk setting flags
456
+ # form_for @user do |f|
457
+ # f.collection_check_boxes :selected_flags, f.object.as_flag_collection('flags', :sent_warm_up_email, :not_follow_up_called), :first, :last
458
+ # end
459
+ def as_flag_collection(colmn = DEFAULT_COLUMN_NAME, *args)
460
+ flags_to_collect = args.empty? ? all_flags(colmn) : args
461
+ collect_flags(*flags_to_collect) do |memo, flag|
462
+ memo << [flag, self.flag_enabled?(flag, colmn)]
463
+ end
464
+ end
465
+
423
466
  private
424
467
 
468
+ def collect_flags(*args)
469
+ args.inject([]) do |memo, flag|
470
+ yield memo, flag
471
+ memo
472
+ end
473
+ end
474
+
425
475
  def get_bit_for(flag, colmn)
426
476
  self.flags(colmn) & self.class.flag_mapping[colmn][flag]
427
477
  end
@@ -1,3 +1,3 @@
1
1
  module FlagShihTzu
2
- VERSION = "0.3.12"
2
+ VERSION = "0.3.13"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flag_shih_tzu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.12
4
+ version: 0.3.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Boling
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2014-10-01 00:00:00.000000000 Z
15
+ date: 2015-03-14 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: activerecord
@@ -142,7 +142,7 @@ files:
142
142
  - ".coveralls.yml"
143
143
  - ".gitignore"
144
144
  - ".travis.yml"
145
- - CHANGELOG
145
+ - CHANGELOG.md
146
146
  - Gemfile
147
147
  - LICENSE
148
148
  - README.md
@@ -183,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
183
  version: '0'
184
184
  requirements: []
185
185
  rubyforge_project:
186
- rubygems_version: 2.2.2
186
+ rubygems_version: 2.4.2
187
187
  signing_key:
188
188
  specification_version: 4
189
189
  summary: Bit fields for ActiveRecord
@@ -192,3 +192,4 @@ test_files:
192
192
  - test/flag_shih_tzu_test.rb
193
193
  - test/schema.rb
194
194
  - test/test_helper.rb
195
+ has_rdoc: