no_integrity 0.3.1 → 0.4.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.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # NoIntegrity
2
+
3
+ ## What is This?
4
+
5
+ Simple hash serialization with loose type coercion. Built for ActiveRecord models, but does not rely specifically on anything from Rails.
6
+
7
+ ## How do I use it?
8
+
9
+ For starters, throw this in your Gemfile:
10
+
11
+ gem "no_integrity"
12
+
13
+ Then, add this to your class:
14
+
15
+ class MrArbitrary < ActiveRecord::Base
16
+ include NoIntegrity
17
+
18
+ attr_accessor :some_random_hash
19
+
20
+ no_attr_store :some_random_hash
21
+ no_attribute :misc
22
+ no_attribute :hair => 'String'
23
+ no_attribute :age => 'Integer'
24
+ no_attribute :height => 'String', :eyes => 'String', :friendly => 'Boolean'
25
+ no_attribute [:cheese, :ham, :balogne]
26
+ end
27
+
28
+ Finally, you can make calls like this:
29
+
30
+ arbs = MrArbitrary.new
31
+ arbs.friendly? # => false
32
+ arbs.friendly = true
33
+ arbs.friendly? # => true
34
+
35
+ You can define as many attributes as you want, and you can specify any of the following coercion types:
36
+
37
+ 1. `String`
38
+ 2. `Integer`
39
+ 3. `Boolean`
40
+
41
+ ## Why?
42
+
43
+ A while back, I needed serialized attributes but it either didn't work for my use case or it wasn't made yet. So, I wrote this gem.
44
+
45
+ ## Contributing
46
+
47
+ __Do not modify the gemspec or version unless you absolutely need to!__
48
+
49
+ 1. Fork it
50
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
51
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
52
+ 4. Push to the branch (`git push origin my-new-feature`)
53
+ 5. Create new Pull Request
54
+
data/Rakefile CHANGED
@@ -1,16 +1,2 @@
1
1
  require 'rubygems'
2
- require 'rake'
3
-
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gemspec|
7
- gemspec.name = "no_integrity"
8
- gemspec.summary = "Key/value store inside of your model."
9
- gemspec.description = "NoIntegrity adds a key/value store inside of your model and then creates the necessary getter/setter methods for accessing those keys as though they were direct attributes of the model."
10
- gemspec.email = "patricktulskie@gmail.com"
11
- gemspec.homepage = "http://localhost"
12
- gemspec.authors = ["Patrick Tulskie"]
13
- end
14
- rescue LoadError
15
- puts "Jeweler not available. Install it with: gem install jeweler"
16
- end
2
+ require 'rake'
@@ -25,21 +25,31 @@ module NoIntegrity
25
25
  if options.is_a?(Hash)
26
26
  options.keys.each do |attrib|
27
27
  @no_attributes[attrib] = options[attrib]
28
- setup_no_attribute_functions(attrib, options[attrib])
28
+ setup_no_attribute_accessors(attrib, options[attrib])
29
+ update_no_attribute_mappings(attrib, options[attrib])
29
30
  end
30
31
  elsif options.is_a?(Array)
31
32
  options.each do |attrib|
32
33
  @no_attributes[attrib] = nil
33
- setup_no_attribute_functions(attrib, nil)
34
+ setup_no_attribute_accessors(attrib, nil)
34
35
  end
35
36
  elsif options.is_a?(Symbol)
36
- setup_no_attribute_functions(options)
37
+ setup_no_attribute_accessors(options)
37
38
  end
38
39
  end
39
40
 
41
+ def no_attribute_mappings
42
+ @no_attribute_mappings
43
+ end
44
+
40
45
  private
41
46
 
42
- def setup_no_attribute_functions(attrib, coercion_type = nil)
47
+ def update_no_attribute_mappings(attrib, type)
48
+ @no_attribute_mappings ||= { }
49
+ @no_attribute_mappings[attrib.to_s] = type
50
+ end
51
+
52
+ def setup_no_attribute_accessors(attrib, coercion_type = nil)
43
53
  module_eval <<-STR
44
54
  def #{attrib}; get_no_attribute('#{attrib}'); end
45
55
  def #{attrib}?; !!get_no_attribute('#{attrib}'); end
@@ -1,3 +1,3 @@
1
1
  module NoIntegrity
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -1,6 +1,15 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe NoIntegrity do
4
+
5
+ context "class methods" do
6
+
7
+ it "stores mappings of the various types of attributes" do
8
+ MrArbitrary.no_attribute_mappings['hair'].should == 'String'
9
+ MrArbitrary.no_attribute_mappings['friendly'].should == 'Boolean'
10
+ end
11
+
12
+ end
4
13
 
5
14
  context "An object with NoIntegrity" do
6
15
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: no_integrity
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 3
9
- - 1
10
- version: 0.3.1
8
+ - 4
9
+ - 0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Patrick Tulskie
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-02-27 00:00:00 -05:00
18
+ date: 2014-05-16 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -62,8 +62,8 @@ extra_rdoc_files: []
62
62
  files:
63
63
  - .gitignore
64
64
  - Gemfile
65
+ - README.md
65
66
  - Rakefile
66
- - VERSION
67
67
  - autotest/discover.rb
68
68
  - lib/no_integrity.rb
69
69
  - lib/no_integrity/no_integrity.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.3.0