no_integrity 0.5.0 → 0.5.2
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 +7 -0
- data/Gemfile +5 -1
- data/lib/no_integrity/no_integrity.rb +10 -14
- data/lib/no_integrity/version.rb +1 -1
- data/spec/no_integrity_spec.rb +50 -50
- data/spec/spec_helper.rb +4 -3
- metadata +35 -58
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 53786fc88468d31ecc8aa8cc51efbd5440bc8504
|
4
|
+
data.tar.gz: 10238f3f6672aee810706ef7d97c64cac2ffb958
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cb9e59afe534b101dcd8649470881516387354f75275b516860a9c178b73b26f33a63465fbea4c3a16b9811127205b1c633b97ffbe8b29f1076af01528d1ffcd
|
7
|
+
data.tar.gz: 90ffc6c02e04e6db40823fb9ec8d3d18d2f80188d124726aba331bc68b60aa747f8ec00503dc60d31bcd3038513130eb7b82db29de22fcd5eada8576b99fa9a8
|
data/Gemfile
CHANGED
@@ -54,7 +54,6 @@ module NoIntegrity
|
|
54
54
|
def alias_no_attr_store(old_name)
|
55
55
|
module_eval <<-STR, __FILE__, __LINE__ + 1
|
56
56
|
def __no_attr_store; self.#{old_name}; end
|
57
|
-
def __no_attr_store?; self.#{old_name}?; end
|
58
57
|
def __no_attr_store=(v); self.#{old_name} = v; end
|
59
58
|
STR
|
60
59
|
end
|
@@ -80,27 +79,24 @@ module NoIntegrity
|
|
80
79
|
private
|
81
80
|
|
82
81
|
def get_no_attribute(attribute_name)
|
83
|
-
|
84
|
-
self.__no_attr_store = normalize_keys(__no_attr_store)
|
82
|
+
initialize_no_attribute_store!
|
85
83
|
no_val = self.__no_attr_store[attribute_name.to_sym]
|
86
84
|
|
87
85
|
no_val.nil? ? no_attribute_mappings[attribute_name.to_sym][:default] : no_val
|
88
86
|
end
|
89
87
|
|
90
88
|
def set_no_attribute(attribute_name, value)
|
91
|
-
|
92
|
-
|
93
|
-
self.__no_attr_store[attribute_name.to_sym] = value
|
94
|
-
else
|
95
|
-
self.__no_attr_store = { attribute_name.to_sym => value }
|
96
|
-
end
|
89
|
+
initialize_no_attribute_store!
|
90
|
+
self.__no_attr_store[attribute_name.to_sym] = value
|
97
91
|
end
|
98
92
|
|
99
|
-
def
|
100
|
-
return
|
101
|
-
|
102
|
-
|
103
|
-
|
93
|
+
def initialize_no_attribute_store!
|
94
|
+
return true if @__initialized_attribute_store
|
95
|
+
# Initialize an empty hash if we are something else...
|
96
|
+
self.__no_attr_store = { } unless self.__no_attr_store.is_a?(Hash)
|
97
|
+
# Symbolize all of the keys
|
98
|
+
self.__no_attr_store = Hash[self.__no_attr_store.map { |k, v| [k.to_sym, v] }]
|
99
|
+
@__initialized_attribute_store = true
|
104
100
|
end
|
105
101
|
|
106
102
|
def coerce_no_attribute_type(value, type)
|
data/lib/no_integrity/version.rb
CHANGED
data/spec/no_integrity_spec.rb
CHANGED
@@ -13,107 +13,107 @@ describe NoIntegrity do
|
|
13
13
|
|
14
14
|
context "An object with NoIntegrity" do
|
15
15
|
|
16
|
-
|
17
|
-
@arbs = MrArbitrary.new
|
18
|
-
end
|
19
|
-
after(:each) do
|
20
|
-
@arbs = nil
|
21
|
-
end
|
16
|
+
let(:arbs) { MrArbitrary.new }
|
22
17
|
|
23
|
-
|
24
|
-
|
25
|
-
end
|
18
|
+
context "that has been initialized" do
|
19
|
+
let(:arbs) { MrArbitrary.new({ hair: 'brown' }) }
|
26
20
|
|
27
|
-
|
28
|
-
|
21
|
+
it "should be able to get all of the attributes" do
|
22
|
+
expect(arbs.__no_attr_store).to be_an_instance_of Hash
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should be able to retrieve attributes from the store" do
|
26
|
+
expect(arbs.hair).to eq('brown')
|
27
|
+
end
|
29
28
|
end
|
30
29
|
|
31
|
-
it "should
|
32
|
-
expect(
|
30
|
+
it "should know where the attributes are being stored" do
|
31
|
+
expect(arbs.class.no_attr_store).to be_an_instance_of Symbol
|
33
32
|
end
|
34
33
|
|
35
|
-
it "should be able to
|
36
|
-
expect(
|
34
|
+
it "should be able to list the attributes it is familiar with" do
|
35
|
+
expect(arbs.no_attributes).to be_an_instance_of Hash
|
37
36
|
end
|
38
37
|
|
39
38
|
it "should be able to have an attribute assigned" do
|
40
|
-
|
41
|
-
expect(
|
39
|
+
arbs.hair = "black"
|
40
|
+
expect(arbs.hair).to eq('black')
|
42
41
|
end
|
43
42
|
|
44
43
|
it "should be able to mass assign attributes" do
|
45
|
-
|
46
|
-
expect(
|
44
|
+
arbs.update_no_attributes( :hair => 'blonde' )
|
45
|
+
expect(arbs.hair).to eq('blonde')
|
47
46
|
end
|
48
47
|
|
49
48
|
it "should coerce boolean types" do
|
50
|
-
|
51
|
-
expect(
|
52
|
-
expect(
|
49
|
+
arbs.friendly = 1
|
50
|
+
expect(arbs).to be_friendly
|
51
|
+
expect(arbs.friendly).to eq(true)
|
53
52
|
end
|
54
53
|
|
55
54
|
it "should coerce interger types" do
|
56
|
-
|
57
|
-
expect(
|
55
|
+
arbs.age = "25"
|
56
|
+
expect(arbs.age).to eq(25)
|
58
57
|
end
|
59
58
|
|
60
59
|
it "should allow arbitrary types" do
|
61
|
-
|
62
|
-
expect(
|
60
|
+
arbs.misc = ['junk']
|
61
|
+
expect(arbs.misc).to eq(['junk'])
|
63
62
|
end
|
64
63
|
|
65
64
|
it "should allow for arrays of arbitary types" do
|
66
|
-
expect(
|
67
|
-
expect(
|
68
|
-
expect(
|
65
|
+
expect(arbs.no_attributes.keys).to include(:cheese)
|
66
|
+
expect(arbs.no_attributes.keys).to include(:ham)
|
67
|
+
expect(arbs.no_attributes.keys).to include(:balogne)
|
69
68
|
end
|
70
69
|
|
71
70
|
it "should allow for hashes of types" do
|
72
|
-
expect(
|
73
|
-
expect(
|
74
|
-
expect(
|
71
|
+
expect(arbs.no_attributes.keys).to include(:height)
|
72
|
+
expect(arbs.no_attributes.keys).to include(:eyes)
|
73
|
+
expect(arbs.no_attributes.keys).to include(:friendly)
|
75
74
|
end
|
76
75
|
|
77
76
|
it "should coerce types on mass assignment" do
|
78
|
-
|
79
|
-
expect(
|
77
|
+
arbs.update_no_attributes(:age => "22")
|
78
|
+
expect(arbs.age).to eq(22)
|
80
79
|
end
|
81
80
|
|
82
81
|
it "should coerce booleans from numbers" do
|
83
|
-
|
84
|
-
expect(
|
85
|
-
|
86
|
-
expect(
|
82
|
+
arbs.friendly = "0"
|
83
|
+
expect(arbs).not_to be_friendly
|
84
|
+
arbs.friendly = "1"
|
85
|
+
expect(arbs).to be_friendly
|
87
86
|
end
|
88
87
|
|
89
88
|
it "should coerce booleans from strings" do
|
90
|
-
|
91
|
-
expect(
|
92
|
-
|
93
|
-
expect(
|
89
|
+
arbs.friendly = "false"
|
90
|
+
expect(arbs).not_to be_friendly
|
91
|
+
arbs.friendly = "true"
|
92
|
+
expect(arbs).to be_friendly
|
94
93
|
end
|
95
94
|
|
96
95
|
it "should not allow mass assignment of attributes if they are not in a hash" do
|
97
|
-
expect {
|
96
|
+
expect { arbs.update_no_attributes("monkey") }.to raise_exception("Type mismatch: I received a String when I was expecting a Hash.")
|
98
97
|
end
|
99
98
|
|
100
99
|
it "should return nil for every attribute if the store is not a hash" do
|
101
|
-
|
102
|
-
expect(
|
100
|
+
arbs.some_random_hash = nil
|
101
|
+
expect(arbs.hair).to be_nil
|
103
102
|
end
|
104
103
|
|
105
104
|
it "should set the store to a hash when setting an attribute" do
|
106
|
-
|
107
|
-
|
108
|
-
expect(
|
105
|
+
arbs.some_random_hash = "POTATO"
|
106
|
+
arbs.eyes = 'red'
|
107
|
+
expect(arbs.eyes).to eq('red')
|
109
108
|
end
|
110
109
|
|
111
110
|
it "should return an empty hash if there are no defined attributes" do
|
112
|
-
expect(
|
111
|
+
expect(arbs.no_attributes).to be_an_instance_of(Hash)
|
113
112
|
end
|
114
113
|
|
115
114
|
it "returns the default value" do
|
116
|
-
expect(
|
115
|
+
expect(arbs.friendly).to eq true
|
116
|
+
expect(arbs.cheese).to eq 'Cheddar'
|
117
117
|
end
|
118
118
|
|
119
119
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'rspec'
|
3
|
+
require 'byebug'
|
3
4
|
require './lib/no_integrity'
|
4
5
|
|
5
6
|
class MrArbitrary
|
@@ -15,12 +16,12 @@ class MrArbitrary
|
|
15
16
|
no_attribute :height, type: 'String'
|
16
17
|
no_attribute :eyes, type: 'String'
|
17
18
|
no_attribute :friendly, type: 'Boolean', default: true
|
18
|
-
no_attribute :cheese
|
19
|
+
no_attribute :cheese, default: "Cheddar"
|
19
20
|
no_attribute :ham
|
20
21
|
no_attribute :balogne
|
21
22
|
|
22
|
-
def initialize(
|
23
|
-
@some_random_hash
|
23
|
+
def initialize(attributes = nil)
|
24
|
+
@some_random_hash = attributes
|
24
25
|
end
|
25
26
|
|
26
27
|
end
|
metadata
CHANGED
@@ -1,50 +1,38 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: no_integrity
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 5
|
9
|
-
- 0
|
10
|
-
version: 0.5.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.2
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Patrick Tulskie
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2016-02-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
22
14
|
name: rspec
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
- - ~>
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
hash: 23
|
30
|
-
segments:
|
31
|
-
- 3
|
32
|
-
- 4
|
33
|
-
- 0
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
34
19
|
version: 3.4.0
|
35
20
|
type: :development
|
36
|
-
|
37
|
-
|
38
|
-
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.4.0
|
27
|
+
description: Add attributes without any sort of integrity to your ActiveRecord or
|
28
|
+
other types of objects.
|
29
|
+
email:
|
39
30
|
- patricktulskie@gmail.com
|
40
31
|
executables: []
|
41
|
-
|
42
32
|
extensions: []
|
43
|
-
|
44
33
|
extra_rdoc_files: []
|
45
|
-
|
46
|
-
|
47
|
-
- .gitignore
|
34
|
+
files:
|
35
|
+
- ".gitignore"
|
48
36
|
- Gemfile
|
49
37
|
- README.md
|
50
38
|
- Rakefile
|
@@ -56,41 +44,30 @@ files:
|
|
56
44
|
- spec/rcov.opts
|
57
45
|
- spec/spec.opts
|
58
46
|
- spec/spec_helper.rb
|
59
|
-
has_rdoc: true
|
60
47
|
homepage: http://github.com/PatrickTulskie/no_integrity
|
61
48
|
licenses: []
|
62
|
-
|
49
|
+
metadata: {}
|
63
50
|
post_install_message:
|
64
51
|
rdoc_options: []
|
65
|
-
|
66
|
-
require_paths:
|
52
|
+
require_paths:
|
67
53
|
- lib
|
68
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
-
|
70
|
-
requirements:
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
71
56
|
- - ">="
|
72
|
-
- !ruby/object:Gem::Version
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
version: "0"
|
77
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
-
none: false
|
79
|
-
requirements:
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
80
61
|
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
|
83
|
-
segments:
|
84
|
-
- 0
|
85
|
-
version: "0"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
86
64
|
requirements: []
|
87
|
-
|
88
65
|
rubyforge_project:
|
89
|
-
rubygems_version:
|
66
|
+
rubygems_version: 2.4.5.1
|
90
67
|
signing_key:
|
91
|
-
specification_version:
|
68
|
+
specification_version: 4
|
92
69
|
summary: Key/value store inside of your model.
|
93
|
-
test_files:
|
70
|
+
test_files:
|
94
71
|
- spec/no_integrity_spec.rb
|
95
72
|
- spec/rcov.opts
|
96
73
|
- spec/spec.opts
|