activemodel_flags 0.1.4 → 0.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ebf8b86b9070587d37159b204cb10364fdb6db1
4
- data.tar.gz: 2595185464b777d6356403cf029eae5552f97d39
3
+ metadata.gz: ec5495baa74e2fc37ea924393119227ff14d9bd5
4
+ data.tar.gz: 475bed55b637c128af293ac75c996583678216b5
5
5
  SHA512:
6
- metadata.gz: 8b30b23dd1add7f674ee5061a0e49bc07909f043cc43958f6e30afd045ff0958ebcdc763da7d13b144d1903baee6c202b60648ccd4945de430485789c7d48ce8
7
- data.tar.gz: 810172a0a4b93fd39de9cd53e3e51954c503110173e82ff70e006c51f9fa36e2d942c7c8b54d747d2a36d0940e88b35288c87e98009a84d2ff6144cb5e01303f
6
+ metadata.gz: df18ec27e31381585545864412467759aaf75e317ce73b29d5036d2a011ab67b0b08d5786fd6f5b4641b8c1e7f20be580febadd689931c4e330a5790da6526ae
7
+ data.tar.gz: 13a6f1f930fc01614255c6f3ede8ffbf22a394701d6be2615afa77235fba81a3cc1f4cc0b4e9714c714f98d659552d0855b1986328d2d7104763360e963238e5
data/.gitignore CHANGED
@@ -3,9 +3,10 @@
3
3
  /Gemfile.lock
4
4
  /_yardoc/
5
5
  /coverage/
6
+ /.idea
6
7
  /doc/
7
8
  /pkg/
8
9
  /spec/reports/
9
10
  /tmp/
10
11
  .DS_Store
11
- /*.gem
12
+ /*.gem
@@ -128,6 +128,29 @@ module ActivemodelFlags
128
128
  self.save!
129
129
  end
130
130
 
131
+
132
+ def method_missing(method)
133
+ if method.to_s =~ /^has_[a-zA-Z0-9_]+\?$/
134
+ key = method.to_s.chomp("?").reverse.chomp("_sah").reverse
135
+ has?(key.to_sym)
136
+ elsif method.to_s =~ /^hasnt_[a-zA-Z0-9_]+\?$/
137
+ key = method.to_s.chomp("?").reverse.chomp("_tnsah").reverse
138
+ hasnt?(key.to_sym)
139
+ elsif method.to_s =~ /^has_[a-zA-Z0-9_]+!$/
140
+ key = method.to_s.chomp("!").reverse.chomp("_sah").reverse
141
+ has!(key.to_sym)
142
+ elsif method.to_s =~ /^hasnt_[a-zA-Z0-9_]+!$/
143
+ key = method.to_s.chomp("!").reverse.chomp("_tnsah").reverse
144
+ hasnt!(key.to_sym)
145
+ else
146
+ super
147
+ end
148
+ end
149
+
150
+ def respond_to?(method, include_private = false)
151
+ has_flag?(method.to_s) || super(method, include_private)
152
+ end
153
+
131
154
  protected
132
155
 
133
156
  def on_flag_change(old_val, new_val)
@@ -1,3 +1,3 @@
1
1
  module ActivemodelFlags
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,7 +1,7 @@
1
1
  module ActivemodelFlags
2
2
  class ColumnGenerator < Rails::Generators::NamedBase
3
3
  include Rails::Generators::Migration
4
- desc "Generates the migration to add a flags column to a rails model."
4
+ desc "Generates the migration to add a JSON flags column to a rails model."
5
5
  source_root File.expand_path('../templates', __FILE__)
6
6
 
7
7
  def manifest
@@ -28,8 +28,8 @@ module ActivemodelFlags
28
28
  assigns[:migration_action] = "add"
29
29
  assigns[:class_name] = "add_flags_fields_to_#{custom_file_name}"
30
30
  assigns[:table_name] = custom_file_name
31
- assigns[:attributes] = [Rails::Generators::GeneratedAttribute.new("flags", "text")]
31
+ assigns[:attributes] = [Rails::Generators::GeneratedAttribute.new("flags", "json")]
32
32
  end
33
33
  end
34
34
  end
35
- end
35
+ end
@@ -1,7 +1,7 @@
1
1
  class AddFlagsTo<%= table_name.camelize %> < ActiveRecord::Migration
2
2
 
3
3
  def up
4
- add_column :<%= table_name %>, :flags, :text, default: '{}'
4
+ add_column :<%= table_name %>, :flags, :json
5
5
  end
6
6
 
7
7
  def down
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activemodel_flags
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jay El-Kaake