schema_reader 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/schema_reader.rb +11 -3
- data/lib/schema_reader/version.rb +1 -1
- data/schema_reader.gemspec +1 -0
- data/spec/lib/schema_reader_spec.rb +58 -0
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82239b56344297db887c8f6e598db2c216bde474
|
4
|
+
data.tar.gz: 9f374935ab0404e7012c8c094fd14ffb2f7bc668
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b280cdb4e09bb509410d62819e68769c95d6122bb2595ac6de52ed8d22acd7b4224100d529769338a14142bafceee5e291f32b23e7d58ec2a611f2820567fc65
|
7
|
+
data.tar.gz: df4fd0de0e15d5c33d290740b3e1937d1a58c54dee68d0ccdb93e7f65163119dd6fe75e6409602335ee8cccdc5e848489d45c6a266e2296ce4c74339dd8e68f1
|
data/lib/schema_reader.rb
CHANGED
@@ -5,9 +5,9 @@ module SchemaReader
|
|
5
5
|
base.extend(ClassMethods)
|
6
6
|
end
|
7
7
|
|
8
|
-
def initialize(options = {})
|
9
|
-
|
10
|
-
end
|
8
|
+
#def initialize(options = {})
|
9
|
+
# update(options)
|
10
|
+
#end
|
11
11
|
|
12
12
|
def update(options = {})
|
13
13
|
options.each do |attribute, value|
|
@@ -18,6 +18,14 @@ module SchemaReader
|
|
18
18
|
|
19
19
|
module ClassMethods
|
20
20
|
|
21
|
+
def pass_attributes_to_new(bool=true)
|
22
|
+
if bool
|
23
|
+
define_method("initialize") do |options|
|
24
|
+
update(options)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
21
29
|
def attr_schema(options = {})
|
22
30
|
table = options.fetch(:table)
|
23
31
|
file = options.fetch(:file)
|
data/schema_reader.gemspec
CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency "bundler", "~> 1.3"
|
23
23
|
spec.add_development_dependency "rake", "~>10.1"
|
24
24
|
spec.add_development_dependency "rspec", "~>2.14"
|
25
|
+
spec.add_development_dependency 'active_hash', '1.2.3'
|
25
26
|
#spec.add_development_dependency "debase", "~>0.0"
|
26
27
|
#spec.add_development_dependency "ruby-debug-ide", "~>0.4"
|
27
28
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'rspec'
|
2
|
+
require 'active_hash'
|
2
3
|
require_relative '../../lib/schema_reader'
|
3
4
|
|
4
5
|
describe SchemaReader do
|
@@ -53,11 +54,53 @@ describe SchemaReader do
|
|
53
54
|
|
54
55
|
end
|
55
56
|
|
57
|
+
describe 'pass_attributes_to_new' do
|
58
|
+
|
59
|
+
it 'has arg of true' do
|
60
|
+
|
61
|
+
class CommentPassableTrue
|
62
|
+
include SchemaReader
|
63
|
+
pass_attributes_to_new true
|
64
|
+
attr_schema table: 'comments',
|
65
|
+
file: File.new('schema.rb', 'r')
|
66
|
+
end
|
67
|
+
|
68
|
+
expect(CommentPassableTrue.new(comment: "comment").comment).to eq('comment')
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'has arg of false' do
|
73
|
+
class CommentPassableFalse
|
74
|
+
include SchemaReader
|
75
|
+
pass_attributes_to_new false
|
76
|
+
attr_schema table: 'comments',
|
77
|
+
file: File.new('schema.rb', 'r')
|
78
|
+
end
|
79
|
+
|
80
|
+
expect { CommentPassableFalse.new(comment: "comment").comment }.to raise_error(ArgumentError)
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'has a default if method not called of false' do
|
85
|
+
|
86
|
+
class CommentPassableDefault
|
87
|
+
include SchemaReader
|
88
|
+
attr_schema table: 'comments',
|
89
|
+
file: File.new('schema.rb', 'r')
|
90
|
+
end
|
91
|
+
|
92
|
+
expect { CommentPassableDefault.new(comment: "comment").comment }.to raise_error(ArgumentError)
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
56
98
|
describe 'associations' do
|
57
99
|
|
58
100
|
before do
|
59
101
|
class Comment
|
60
102
|
include SchemaReader
|
103
|
+
pass_attributes_to_new :true
|
61
104
|
attr_schema table: 'comments',
|
62
105
|
file: File.new('schema.rb', 'r')
|
63
106
|
end
|
@@ -80,4 +123,19 @@ describe SchemaReader do
|
|
80
123
|
|
81
124
|
end
|
82
125
|
|
126
|
+
describe 'compatibility with ActiveHash' do
|
127
|
+
|
128
|
+
before do
|
129
|
+
class ActiveUser < ActiveHash::Base
|
130
|
+
include SchemaReader
|
131
|
+
pass_attributes_to_new false
|
132
|
+
fields *read_schema('users', File.new('schema.rb', 'r'))
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'will have attributes from the schema file' do
|
137
|
+
expect(ActiveUser.create(name: 'Joe').name).to eq 'Joe'
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
83
141
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schema_reader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dustin Zeisler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '2.14'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: active_hash
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.2.3
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.2.3
|
55
69
|
description: Reads Rails Database schema and creates a class from selected table with
|
56
70
|
getters and setters.
|
57
71
|
email:
|