attr_object 0.0.2 → 0.0.3
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 +4 -4
- data/lib/attr_object/version.rb +1 -1
- data/lib/generators/attr_object/USAGE +10 -0
- data/lib/generators/attr_object/attr_object_generator.rb +22 -0
- data/lib/generators/attr_object/templates/attr_object.rb +2 -0
- data/test/{value_object_test.rb → attr_object_test.rb} +5 -10
- data/test/dummy/app/attr_objects/{phone_value.rb → phone_attr.rb} +1 -1
- data/test/dummy/app/attr_objects/{position_value.rb → position_attr.rb} +1 -1
- data/test/dummy/app/models/user.rb +2 -2
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/test.log +28 -0
- data/test/dummy/tmp/generators/app/attr_objects/position_attr.rb +2 -0
- data/test/lib/generators/attr_object_generator_test.rb +32 -0
- metadata +14 -9
- data/test/dummy/tmp/generators/app/attr_objects/phone_attr.rb +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6553f9b64e829966f46fe040a9f23e6723f8573d
|
4
|
+
data.tar.gz: d4e32fbf0fc83f86cbbc9d6912c68d46e78e7791
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6ab2ee78fbedd7ab76b602223b70bdc7057251526c08bec6643455ba82df517e06cd2ff33d7b6537dfc66a93bc004bcc19d7950e7aaa8038fba348e50eb1b00
|
7
|
+
data.tar.gz: c145f8f9c19872c1cc427472ea6dc2ef2660de7c522b0f5b61691427ef3eeee7bb79858128a9a5cf2af5cdea5aad38ba9be4cea0b3aad03ede88693be7a1579c
|
data/lib/attr_object/version.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
class AttrObjectGenerator < Rails::Generators::NamedBase
|
2
|
+
source_root File.expand_path('../templates', __FILE__)
|
3
|
+
|
4
|
+
def create_attr_object_file
|
5
|
+
#template "attr_object.rb", File.join('app/attr_objects/phone_attr.rb')
|
6
|
+
template "attr_object.rb", "app/attr_objects/#{lower_class_name}_attr.rb"
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
def class_name
|
11
|
+
file_name.classify
|
12
|
+
end
|
13
|
+
|
14
|
+
def lower_class_name
|
15
|
+
class_name.underscore
|
16
|
+
end
|
17
|
+
|
18
|
+
def class_delegate
|
19
|
+
del = self.args.first
|
20
|
+
del.classify if del
|
21
|
+
end
|
22
|
+
end
|
@@ -1,15 +1,10 @@
|
|
1
1
|
require 'test_helper'
|
2
|
-
|
3
2
|
require 'minitest/spec'
|
4
3
|
|
5
4
|
describe AttrObject do
|
6
5
|
DEFAULT_PHONE = "959-542-5256"
|
7
6
|
DEFAULT_MOBILE = "878-858-5115"
|
8
7
|
|
9
|
-
def userz(phone: DEFAULT_PHONE, mobile: DEFAULT_MOBILE, position: nil)
|
10
|
-
User.new phone: phone, mobile: mobile, position: position
|
11
|
-
end
|
12
|
-
|
13
8
|
let(:user) do
|
14
9
|
User.new phone: DEFAULT_PHONE, mobile: DEFAULT_MOBILE
|
15
10
|
end
|
@@ -25,10 +20,10 @@ describe AttrObject do
|
|
25
20
|
end
|
26
21
|
end
|
27
22
|
|
28
|
-
describe
|
23
|
+
describe PhoneAttr do
|
29
24
|
it "should return the right class on the attribute" do
|
30
|
-
assert user.phone.is_a?(
|
31
|
-
assert user.mobile.is_a?(
|
25
|
+
assert user.phone.is_a?(PhoneAttr), "`phone` should be PhoneValue"
|
26
|
+
assert user.mobile.is_a?(PhoneAttr), "`mobile` should be PhoneValue"
|
32
27
|
end
|
33
28
|
|
34
29
|
it "should call a method from the value object" do
|
@@ -57,13 +52,13 @@ describe AttrObject do
|
|
57
52
|
end
|
58
53
|
end
|
59
54
|
|
60
|
-
describe
|
55
|
+
describe PositionAttr do
|
61
56
|
let(:user) do
|
62
57
|
User.new position: 0
|
63
58
|
end
|
64
59
|
|
65
60
|
it "`position` should be a PositionValue" do
|
66
|
-
_(user.position).must_be_instance_of
|
61
|
+
_(user.position).must_be_instance_of PositionAttr
|
67
62
|
end
|
68
63
|
|
69
64
|
it "`position` should be updated as a `Fixnum`" do
|
data/test/dummy/db/test.sqlite3
CHANGED
Binary file
|
data/test/dummy/log/test.log
CHANGED
@@ -15018,3 +15018,31 @@ AttrObjectGeneratorTest: test_generator_runs_without_errors
|
|
15018
15018
|
[1m[36mSQL (0.1ms)[0m [1mINSERT INTO "users" ("position", "created_at", "updated_at") VALUES (?, ?, ?)[0m [["position", 1], ["created_at", "2016-01-12 11:44:25.913970"], ["updated_at", "2016-01-12 11:44:25.913970"]]
|
15019
15019
|
[1m[35m (22.2ms)[0m commit transaction
|
15020
15020
|
[1m[36mUser Load (0.1ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1[0m [["id", 511]]
|
15021
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
15022
|
+
[1m[35m (0.1ms)[0m begin transaction
|
15023
|
+
[1m[36mSQL (0.3ms)[0m [1mINSERT INTO "users" ("position", "created_at", "updated_at") VALUES (?, ?, ?)[0m [["position", 99], ["created_at", "2016-01-12 11:49:21.780995"], ["updated_at", "2016-01-12 11:49:21.780995"]]
|
15024
|
+
[1m[35m (16.5ms)[0m commit transaction
|
15025
|
+
[1m[36mUser Load (0.2ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1[0m [["id", 512]]
|
15026
|
+
[1m[35m (0.1ms)[0m begin transaction
|
15027
|
+
[1m[36mSQL (0.1ms)[0m [1mINSERT INTO "users" ("position", "created_at", "updated_at") VALUES (?, ?, ?)[0m [["position", 0], ["created_at", "2016-01-12 11:49:21.810000"], ["updated_at", "2016-01-12 11:49:21.810000"]]
|
15028
|
+
[1m[35m (24.7ms)[0m commit transaction
|
15029
|
+
[1m[36mUser Load (0.1ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1[0m [["id", 513]]
|
15030
|
+
[1m[35m (0.1ms)[0m begin transaction
|
15031
|
+
[1m[36mSQL (0.1ms)[0m [1mINSERT INTO "users" ("position", "created_at", "updated_at") VALUES (?, ?, ?)[0m [["position", 1], ["created_at", "2016-01-12 11:49:21.837698"], ["updated_at", "2016-01-12 11:49:21.837698"]]
|
15032
|
+
[1m[35m (12.8ms)[0m commit transaction
|
15033
|
+
[1m[36mUser Load (0.1ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1[0m [["id", 514]]
|
15034
|
+
[1m[35m (0.1ms)[0m begin transaction
|
15035
|
+
----------------------------------------------------------
|
15036
|
+
AttrObjectGeneratorTest: test_generator_with_invalid_class
|
15037
|
+
----------------------------------------------------------
|
15038
|
+
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
15039
|
+
[1m[35m (0.0ms)[0m begin transaction
|
15040
|
+
-----------------------------------------------------------
|
15041
|
+
AttrObjectGeneratorTest: test_generator_runs_without_errors
|
15042
|
+
-----------------------------------------------------------
|
15043
|
+
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
15044
|
+
[1m[35m (0.0ms)[0m begin transaction
|
15045
|
+
--------------------------------------------------
|
15046
|
+
AttrObjectGeneratorTest: test_generator_with_class
|
15047
|
+
--------------------------------------------------
|
15048
|
+
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'generators/attr_object/attr_object_generator'
|
3
|
+
|
4
|
+
class AttrObjectGeneratorTest < Rails::Generators::TestCase
|
5
|
+
tests AttrObjectGenerator
|
6
|
+
destination Rails.root.join('tmp/generators')
|
7
|
+
setup :prepare_destination
|
8
|
+
|
9
|
+
test "generator runs without errors" do
|
10
|
+
assert_nothing_raised do
|
11
|
+
run_generator %w[phone]
|
12
|
+
end
|
13
|
+
|
14
|
+
assert_file "app/attr_objects/phone_attr.rb", /class PhoneAttr/
|
15
|
+
end
|
16
|
+
|
17
|
+
test "generator with class" do
|
18
|
+
assert_nothing_raised do
|
19
|
+
run_generator %w[position fixnum]
|
20
|
+
end
|
21
|
+
|
22
|
+
assert_file "app/attr_objects/position_attr.rb", /class PositionAttr < DelegateClass\(Fixnum\)/
|
23
|
+
end
|
24
|
+
|
25
|
+
test "generator with invalid class" do
|
26
|
+
assert_nothing_raised do
|
27
|
+
run_generator %w[phone invalid_ruby_class]
|
28
|
+
end
|
29
|
+
|
30
|
+
assert_file "app/attr_objects/phone_attr.rb", /class PhoneAttr < DelegateClass\(InvalidRubyClass\)/
|
31
|
+
end
|
32
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attr_object
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- dsimard
|
@@ -50,13 +50,17 @@ files:
|
|
50
50
|
- Rakefile
|
51
51
|
- lib/attr_object.rb
|
52
52
|
- lib/attr_object/version.rb
|
53
|
+
- lib/generators/attr_object/USAGE
|
54
|
+
- lib/generators/attr_object/attr_object_generator.rb
|
55
|
+
- lib/generators/attr_object/templates/attr_object.rb
|
53
56
|
- lib/tasks/attr_object_tasks.rake
|
57
|
+
- test/attr_object_test.rb
|
54
58
|
- test/dummy/README.rdoc
|
55
59
|
- test/dummy/Rakefile
|
56
60
|
- test/dummy/app/assets/javascripts/application.js
|
57
61
|
- test/dummy/app/assets/stylesheets/application.css
|
58
|
-
- test/dummy/app/attr_objects/
|
59
|
-
- test/dummy/app/attr_objects/
|
62
|
+
- test/dummy/app/attr_objects/phone_attr.rb
|
63
|
+
- test/dummy/app/attr_objects/position_attr.rb
|
60
64
|
- test/dummy/app/controllers/application_controller.rb
|
61
65
|
- test/dummy/app/helpers/application_helper.rb
|
62
66
|
- test/dummy/app/models/user.rb
|
@@ -98,9 +102,9 @@ files:
|
|
98
102
|
- test/dummy/public/favicon.ico
|
99
103
|
- test/dummy/test/fixtures/users.yml
|
100
104
|
- test/dummy/test/models/user_test.rb
|
101
|
-
- test/dummy/tmp/generators/app/attr_objects/
|
105
|
+
- test/dummy/tmp/generators/app/attr_objects/position_attr.rb
|
106
|
+
- test/lib/generators/attr_object_generator_test.rb
|
102
107
|
- test/test_helper.rb
|
103
|
-
- test/value_object_test.rb
|
104
108
|
homepage: https://github.com/dsimard/attr_object
|
105
109
|
licenses:
|
106
110
|
- MIT
|
@@ -126,17 +130,16 @@ signing_key:
|
|
126
130
|
specification_version: 4
|
127
131
|
summary: Value Objects for Ruby on Rails
|
128
132
|
test_files:
|
129
|
-
- test/value_object_test.rb
|
130
133
|
- test/dummy/Rakefile
|
131
134
|
- test/dummy/app/controllers/application_controller.rb
|
132
135
|
- test/dummy/app/helpers/application_helper.rb
|
133
136
|
- test/dummy/app/models/user.rb
|
134
137
|
- test/dummy/app/views/layouts/application.html.erb
|
135
|
-
- test/dummy/app/attr_objects/
|
136
|
-
- test/dummy/app/attr_objects/
|
138
|
+
- test/dummy/app/attr_objects/phone_attr.rb
|
139
|
+
- test/dummy/app/attr_objects/position_attr.rb
|
137
140
|
- test/dummy/app/assets/stylesheets/application.css
|
138
141
|
- test/dummy/app/assets/javascripts/application.js
|
139
|
-
- test/dummy/tmp/generators/app/attr_objects/
|
142
|
+
- test/dummy/tmp/generators/app/attr_objects/position_attr.rb
|
140
143
|
- test/dummy/README.rdoc
|
141
144
|
- test/dummy/public/500.html
|
142
145
|
- test/dummy/public/422.html
|
@@ -175,5 +178,7 @@ test_files:
|
|
175
178
|
- test/dummy/bin/setup
|
176
179
|
- test/dummy/bin/rails
|
177
180
|
- test/dummy/bin/rake
|
181
|
+
- test/attr_object_test.rb
|
178
182
|
- test/test_helper.rb
|
183
|
+
- test/lib/generators/attr_object_generator_test.rb
|
179
184
|
has_rdoc:
|