data_guru 1.0.0 → 1.1.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 +4 -4
- data/.rubocop.yml +1 -0
- data/Guardfile +12 -0
- data/README.md +46 -2
- data/bin/_guard-core +16 -0
- data/bin/guard +16 -0
- data/bin/rspec +16 -0
- data/bin/rubocop +16 -0
- data/data_guru.gemspec +2 -0
- data/lib/data_guru.rb +2 -0
- data/lib/data_guru/client.rb +24 -7
- data/lib/data_guru/collection.rb +6 -13
- data/lib/data_guru/exceptions.rb +14 -0
- data/lib/data_guru/invalid_values.rb +49 -0
- data/lib/data_guru/model.rb +21 -14
- data/lib/data_guru/model_configuration.rb +9 -19
- data/lib/data_guru/validation.rb +2 -2
- data/lib/data_guru/validations/configuration.rb +2 -2
- data/lib/data_guru/validations/model_configuration.rb +28 -33
- data/lib/data_guru/version.rb +1 -1
- metadata +37 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf330d25b127f1da2f00404a6f4ecf142138effe
|
4
|
+
data.tar.gz: 9ad2c100a458d829ef2eb8ead64699fa48017b1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 218cd813a01bdda3951e8e6470450a292e913b6af31b1c805f711e089fcdba266f27656cf26de64ae6f71459afc7943fc1ac167b33021ada4354b1f1f58f968e
|
7
|
+
data.tar.gz: 9e0b53bb35dde722135124f95e7170f6e29a25228662cecf7965fea3ee8a995ab77c27236f9063fa081521255da0545de1d1560ed9c24a48cb84e3be9860f0d7
|
data/.rubocop.yml
CHANGED
data/Guardfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
group :red_green_refactor, halt_on_fail: true do
|
2
|
+
guard :rspec, cmd: "bin/rspec" do
|
3
|
+
watch(%r{^spec/.+_spec\.rb$})
|
4
|
+
watch(%r{^lib/data_guru/(.+)\.rb$}) { |m| "spec/data_guru/#{m[1]}_spec.rb" }
|
5
|
+
watch("spec/spec_helper.rb") { "spec" }
|
6
|
+
end
|
7
|
+
|
8
|
+
guard :rubocop, all_on_start: false, cli: ["--auto-correct"] do
|
9
|
+
watch(/.+\.rb$/)
|
10
|
+
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
|
11
|
+
end
|
12
|
+
end
|
data/README.md
CHANGED
@@ -87,18 +87,62 @@ member = data.members.all.first
|
|
87
87
|
# to get list of member attributes
|
88
88
|
member.attributes
|
89
89
|
|
90
|
-
# to get list of permitted and required attributes (see
|
90
|
+
# to get list of permitted and required attributes (see Permissions section below)
|
91
91
|
member.permitted_attributes
|
92
92
|
member.required_attributes
|
93
93
|
|
94
|
-
# check if member has all required attributes set
|
94
|
+
# check if member has all required attributes set with valid datatypes
|
95
95
|
member.valid?
|
96
96
|
member.missing_attributes
|
97
|
+
member.invalid_data_type_attributes
|
97
98
|
```
|
98
99
|
|
99
100
|
Each model has a set of getter methods (`permitted_attributes`), so for example you can do `member.github` to get just the github membername.
|
100
101
|
Each model also has `id` method which returns the name of the file the member is stored in, for example it will return `john.doe` for the member in the file `john.doe.yml`.
|
101
102
|
|
103
|
+
To check if files in your Permissions repo contain valid information you can run:
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
DataGuru::Client.new.invalid_values
|
107
|
+
```
|
108
|
+
|
109
|
+
You will get a hash with names of invalid files and values which are missing or have invalid datatype:
|
110
|
+
|
111
|
+
```ruby
|
112
|
+
# {
|
113
|
+
# "john.doe.yml" => {
|
114
|
+
# "missing_attributes" => [:emails, :external],
|
115
|
+
# "invalid_data_type_attributes" => [:github]
|
116
|
+
# }
|
117
|
+
# }
|
118
|
+
```
|
119
|
+
|
120
|
+
You can also check invalid values of particular collection:
|
121
|
+
|
122
|
+
```ruby
|
123
|
+
DataGuru::Client.new.invalid_values("users")
|
124
|
+
```
|
125
|
+
|
126
|
+
If you want to check a particular value in a collection, you need to specify collection name and value name:
|
127
|
+
|
128
|
+
```ruby
|
129
|
+
DataGuru::Client.new.invalid_values("users", "email")
|
130
|
+
|
131
|
+
```
|
132
|
+
|
133
|
+
You will get an array containing names of files from "users" collection which have invalid "email" value:
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
# ["john.doe.yml", "jane.foe.yml"]
|
137
|
+
|
138
|
+
```
|
139
|
+
|
140
|
+
You can also pass parameters as symbols:
|
141
|
+
|
142
|
+
```ruby
|
143
|
+
DataGuru::Client.new.invalid_values(:users, :email)
|
144
|
+
```
|
145
|
+
|
102
146
|
You can check whether configuration (in your rails app) and model configuration (in your permissions repo) is valid by running `DataGuru::Client.new.errors`.
|
103
147
|
|
104
148
|
### Permissions
|
data/bin/_guard-core
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application '_guard-core' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require "pathname"
|
10
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require "rubygems"
|
14
|
+
require "bundler/setup"
|
15
|
+
|
16
|
+
load Gem.bin_path("guard", "_guard-core")
|
data/bin/guard
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'guard' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require "pathname"
|
10
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require "rubygems"
|
14
|
+
require "bundler/setup"
|
15
|
+
|
16
|
+
load Gem.bin_path("guard", "guard")
|
data/bin/rspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'rspec' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require "pathname"
|
10
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require "rubygems"
|
14
|
+
require "bundler/setup"
|
15
|
+
|
16
|
+
load Gem.bin_path("rspec-core", "rspec")
|
data/bin/rubocop
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'rubocop' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require "pathname"
|
10
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require "rubygems"
|
14
|
+
require "bundler/setup"
|
15
|
+
|
16
|
+
load Gem.bin_path("rubocop", "rubocop")
|
data/data_guru.gemspec
CHANGED
@@ -27,4 +27,6 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.add_development_dependency "rake", "~> 10.0"
|
28
28
|
spec.add_development_dependency "rspec"
|
29
29
|
spec.add_development_dependency "rubocop"
|
30
|
+
spec.add_development_dependency "guard-rspec"
|
31
|
+
spec.add_development_dependency "guard-rubocop"
|
30
32
|
end
|
data/lib/data_guru.rb
CHANGED
data/lib/data_guru/client.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
module DataGuru
|
2
2
|
class Client
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "httparty"
|
4
|
+
require "active_support/core_ext/string"
|
5
5
|
|
6
6
|
def initialize(api_url: nil, access_token: nil)
|
7
|
-
if api_url.
|
8
|
-
|
9
|
-
access_token: access_token)
|
10
|
-
end
|
7
|
+
return if api_url.blank? || access_token.blank?
|
8
|
+
DataGuru.config = Configuration.new(api_url: api_url, access_token: access_token)
|
11
9
|
end
|
12
10
|
|
13
11
|
def method_missing(name)
|
14
12
|
create_model_class(name) if should_create_class?(name)
|
15
|
-
value = DataGuru::Collection.new(collection_name: name,
|
13
|
+
value = DataGuru::Collection.new(collection_name: name,
|
14
|
+
model: model(name),
|
15
|
+
config_data: config_data[config_key(name)])
|
16
16
|
get_variable(name) || set_variable(name, value)
|
17
17
|
end
|
18
18
|
|
@@ -25,6 +25,14 @@ module DataGuru
|
|
25
25
|
DataGuru::Validation.new.errors
|
26
26
|
end
|
27
27
|
|
28
|
+
def invalid_values(collection = "", attribute = "")
|
29
|
+
DataGuru::InvalidValues.new(self, collection, attribute).call
|
30
|
+
end
|
31
|
+
|
32
|
+
def config_data
|
33
|
+
@config_data ||= HTTParty.get(config_resource_url)
|
34
|
+
end
|
35
|
+
|
28
36
|
private
|
29
37
|
|
30
38
|
def should_create_class?(name)
|
@@ -64,6 +72,7 @@ module DataGuru
|
|
64
72
|
def wipe_collections_cache
|
65
73
|
collection_names.each { |name| instance_variable_set("@#{name}", nil) }
|
66
74
|
instance_variable_set("@collection_names", nil)
|
75
|
+
instance_variable_set("@config_data", nil)
|
67
76
|
end
|
68
77
|
|
69
78
|
def refresh_data_url
|
@@ -77,5 +86,13 @@ module DataGuru
|
|
77
86
|
def collection_names_url
|
78
87
|
"#{DataGuru.config.api_url}/?token=#{DataGuru.config.access_token}"
|
79
88
|
end
|
89
|
+
|
90
|
+
def config_resource_url
|
91
|
+
"#{DataGuru.config.api_url}/collections/config?token=#{DataGuru.config.access_token}"
|
92
|
+
end
|
93
|
+
|
94
|
+
def config_key(name)
|
95
|
+
name.to_s.singularize
|
96
|
+
end
|
80
97
|
end
|
81
98
|
end
|
data/lib/data_guru/collection.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
module DataGuru
|
2
2
|
class Collection
|
3
3
|
include Enumerable
|
4
|
-
require
|
4
|
+
require "httparty"
|
5
5
|
|
6
|
-
attr_reader :collection_name, :model, :config
|
6
|
+
attr_reader :collection_name, :model, :config_data, :config
|
7
7
|
|
8
|
-
def initialize(collection_name:, model:, config: default_config(model))
|
8
|
+
def initialize(collection_name:, model:, config_data:, config: default_config(model, config_data))
|
9
9
|
@collection_name = collection_name
|
10
10
|
@model = model
|
11
11
|
@config = config
|
12
|
+
@config_data = config_data
|
12
13
|
end
|
13
14
|
|
14
15
|
def all
|
@@ -21,8 +22,8 @@ module DataGuru
|
|
21
22
|
|
22
23
|
private
|
23
24
|
|
24
|
-
def default_config(model)
|
25
|
-
DataGuru::ModelConfiguration.new(model: model)
|
25
|
+
def default_config(model, config_data)
|
26
|
+
DataGuru::ModelConfiguration.new(model: model, config_data: config_data)
|
26
27
|
end
|
27
28
|
|
28
29
|
def build_models(collection_type)
|
@@ -36,14 +37,6 @@ module DataGuru
|
|
36
37
|
"?token=#{DataGuru.config.access_token}"
|
37
38
|
end
|
38
39
|
|
39
|
-
def config_resource_url
|
40
|
-
"#{DataGuru.config.api_url}/collections/config?token=#{DataGuru.config.access_token}"
|
41
|
-
end
|
42
|
-
|
43
|
-
def config_data
|
44
|
-
@config_data ||= HTTParty.get(config_resource_url)
|
45
|
-
end
|
46
|
-
|
47
40
|
def data(collection_type)
|
48
41
|
HTTParty.get(collection_resource_url(collection_type))
|
49
42
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module DataGuru
|
2
|
+
class MissingValue < StandardError
|
3
|
+
attr_reader :attribute, :collection_name
|
4
|
+
|
5
|
+
def initialize(attribute, collection_name)
|
6
|
+
@attribute = attribute
|
7
|
+
@collection_name = collection_name
|
8
|
+
end
|
9
|
+
|
10
|
+
def message
|
11
|
+
"Value '#{attribute}' does not exist for '#{collection_name}' collection"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module DataGuru
|
2
|
+
class InvalidValues
|
3
|
+
attr_reader :data, :collection_name, :attribute, :invalid_files
|
4
|
+
|
5
|
+
TYPES = %w(missing_attributes invalid_data_type_attributes)
|
6
|
+
|
7
|
+
def initialize(data, collection_name, attribute)
|
8
|
+
@data = data
|
9
|
+
@collection_name = collection_name
|
10
|
+
@attribute = attribute
|
11
|
+
@invalid_files = []
|
12
|
+
end
|
13
|
+
|
14
|
+
def call
|
15
|
+
collection_names.each { |collection_name| get_invalid_files(collection_name) }
|
16
|
+
invalid_values = invalid_files.each_with_object({}) do |file, h|
|
17
|
+
h["#{file.id}.yml"] = get_invalid_values(file)
|
18
|
+
end
|
19
|
+
attribute.present? ? files_with_invalid_attribute(attribute, invalid_values) : invalid_values
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def get_invalid_values(file)
|
25
|
+
TYPES.each_with_object({}) do |type, h|
|
26
|
+
h[type] = file.send(type) unless file.send(type).empty?
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_invalid_files(collection_name)
|
31
|
+
data.send(collection_name).each do |file|
|
32
|
+
invalid_files << file unless file.valid?
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def collection_names
|
37
|
+
collection_name.present? ? [collection_name] : data.send(:collection_names) - ["config"]
|
38
|
+
end
|
39
|
+
|
40
|
+
def files_with_invalid_attribute(attribute, h)
|
41
|
+
fail DataGuru::MissingValue.new(attribute, collection_name).message unless value_exists?
|
42
|
+
h.map { |k, v| k if v.to_s.include?(attribute.to_s) }.compact
|
43
|
+
end
|
44
|
+
|
45
|
+
def value_exists?
|
46
|
+
data.send(collection_name).config_data.keys.include? attribute.to_s
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/data_guru/model.rb
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
module DataGuru
|
2
2
|
module Model
|
3
|
-
attr_reader :permitted_attributes, :required_attributes, :id
|
3
|
+
attr_reader :permitted_attributes, :required_attributes, :data_types, :id
|
4
4
|
|
5
5
|
def initialize(key, attrs, config, config_data)
|
6
6
|
@id = key
|
7
|
-
@permitted_attributes = config.permitted_attributes
|
8
|
-
@required_attributes = config.required_attributes
|
7
|
+
@permitted_attributes = config.permitted_attributes
|
8
|
+
@required_attributes = config.required_attributes
|
9
|
+
@data_types = config.data_types
|
9
10
|
|
10
11
|
permitted_attributes.each do |attribute|
|
11
12
|
set_attr_getter(attribute)
|
12
|
-
default_value =
|
13
|
+
default_value = config_data[attribute.to_s]["default_value"]
|
13
14
|
set_attr_value(attribute, attrs[attribute.to_s], default_value)
|
14
15
|
end
|
15
16
|
end
|
@@ -19,19 +20,29 @@ module DataGuru
|
|
19
20
|
end
|
20
21
|
|
21
22
|
def valid?
|
22
|
-
|
23
|
+
missing_attributes.empty? && invalid_data_type_attributes.empty?
|
23
24
|
end
|
24
25
|
|
25
26
|
def missing_attributes
|
26
27
|
required_attributes - present_required_attributes
|
27
28
|
end
|
28
29
|
|
30
|
+
def invalid_data_type_attributes
|
31
|
+
data_types.map do |name, value|
|
32
|
+
next if attributes[name].nil?
|
33
|
+
if value == "boolean"
|
34
|
+
name unless [true, false].include? attributes[name]
|
35
|
+
else
|
36
|
+
name unless attributes[name].class == value.classify.constantize
|
37
|
+
end
|
38
|
+
end
|
39
|
+
.compact
|
40
|
+
end
|
41
|
+
|
29
42
|
private
|
30
43
|
|
31
44
|
def set_attr_getter(attribute)
|
32
|
-
self.class.send(:define_method, attribute)
|
33
|
-
instance_variable_get("@#{attribute}")
|
34
|
-
end
|
45
|
+
self.class.send(:define_method, attribute) { instance_variable_get("@#{attribute}") }
|
35
46
|
end
|
36
47
|
|
37
48
|
def set_attr_value(attribute, value, default_value)
|
@@ -40,15 +51,11 @@ module DataGuru
|
|
40
51
|
end
|
41
52
|
|
42
53
|
def present_required_attributes
|
43
|
-
required_attributes.map
|
44
|
-
!attributes[name].nil? ? name : nil
|
45
|
-
end
|
54
|
+
required_attributes.map { |name| attributes[name].present? ? name : nil }
|
46
55
|
end
|
47
56
|
|
48
57
|
def all_attributes
|
49
|
-
|
50
|
-
.map{ |name| [name, public_send(name)] } << [:id, id]
|
51
|
-
Hash[attrs]
|
58
|
+
permitted_attributes.each_with_object({ id: id }) { |name, h| h[name] = public_send(name) }
|
52
59
|
end
|
53
60
|
end
|
54
61
|
end
|
@@ -1,32 +1,22 @@
|
|
1
1
|
module DataGuru
|
2
2
|
class ModelConfiguration
|
3
|
-
attr_reader :model, :
|
3
|
+
attr_reader :model, :config_data
|
4
4
|
|
5
|
-
def initialize(model:,
|
5
|
+
def initialize(model:, config_data:)
|
6
6
|
@model = model
|
7
|
-
@
|
7
|
+
@config_data = config_data.try(:symbolize_keys)
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
11
|
-
config_data
|
10
|
+
def permitted_attributes
|
11
|
+
config_data.keys
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
15
|
-
|
14
|
+
def required_attributes
|
15
|
+
config_data.select{ |_k,v| v['required'] }.keys
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
def default_model_name(model)
|
25
|
-
model.name.split('::').last
|
26
|
-
.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
|
27
|
-
.gsub(/([a-z\d])([A-Z])/,'\1_\2')
|
28
|
-
.tr("-", "_")
|
29
|
-
.downcase
|
18
|
+
def data_types
|
19
|
+
config_data.each_with_object({}) { |(k, v), h| h[k] = v["value_type"] }
|
30
20
|
end
|
31
21
|
end
|
32
22
|
end
|
data/lib/data_guru/validation.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module DataGuru
|
2
2
|
class Validation
|
3
|
-
require
|
3
|
+
require "httparty"
|
4
4
|
attr_reader :config, :keys
|
5
5
|
|
6
6
|
TYPES = %w(configuration model_configuration)
|
@@ -11,7 +11,7 @@ module DataGuru
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def errors
|
14
|
-
TYPES.flat_map{ |type| send("#{type}_errors") }
|
14
|
+
TYPES.flat_map { |type| send("#{type}_errors") }
|
15
15
|
end
|
16
16
|
|
17
17
|
private
|
@@ -3,9 +3,9 @@ module DataGuru
|
|
3
3
|
attr_reader :config, :keys
|
4
4
|
|
5
5
|
VALIDATIONS = %w(config model_file model_attributes model_attribute_name
|
6
|
-
|
6
|
+
model_attribute_content)
|
7
7
|
RESERVED_WORDS = %w(id attributes permitted_attributes required_attributes
|
8
|
-
|
8
|
+
missing_attributes valid?)
|
9
9
|
ATTRIBUTE_TYPES = %w(required default_value value_type)
|
10
10
|
|
11
11
|
def initialize(config, keys)
|
@@ -21,7 +21,7 @@ module DataGuru
|
|
21
21
|
private
|
22
22
|
|
23
23
|
def model_names
|
24
|
-
keys.map(&:singularize) - [
|
24
|
+
keys.map(&:singularize) - ["config"]
|
25
25
|
end
|
26
26
|
|
27
27
|
def valid?
|
@@ -36,41 +36,35 @@ module DataGuru
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def config_valid?
|
39
|
-
keys.include?(
|
39
|
+
keys.include?("config")
|
40
40
|
end
|
41
41
|
|
42
42
|
def model_file_valid?
|
43
43
|
return false unless config_valid?
|
44
|
-
|
45
|
-
.map{ |name| config.include?(name) }
|
46
|
-
.select{ |name| name }
|
47
|
-
valid_files.size == model_names.size
|
44
|
+
model_names.count { |name| config.include?(name) } == model_names.size
|
48
45
|
end
|
49
46
|
|
50
47
|
def model_attributes_valid?
|
51
48
|
return false unless model_file_valid?
|
52
|
-
|
53
|
-
.map{ |name| config[name] == false || config[name].nil? }
|
54
|
-
.select{ |name| !name }
|
55
|
-
valid_models.size == model_names.size
|
49
|
+
model_names.count { |name| config[name] == false || config[name].nil? } == model_names.size
|
56
50
|
end
|
57
51
|
|
58
52
|
def model_attribute_name_valid?
|
59
|
-
attributes = present_models.flat_map{ |model| config[model].keys }
|
53
|
+
attributes = present_models.flat_map { |model| config[model].keys }
|
60
54
|
diff = attributes - RESERVED_WORDS
|
61
55
|
attributes.count == diff.count
|
62
56
|
end
|
63
57
|
|
64
58
|
def model_attribute_content_valid?
|
65
|
-
attributes = present_models.map{ |model| config[model] }
|
66
|
-
invalid_attrs = attributes.flat_map
|
67
|
-
|
68
|
-
|
59
|
+
attributes = present_models.map { |model| config[model] }
|
60
|
+
invalid_attrs = attributes.flat_map do |model|
|
61
|
+
model.values.map { |attrs| attrs.keys.sort == ATTRIBUTE_TYPES.sort }
|
62
|
+
end.select(&:!)
|
69
63
|
invalid_attrs.size == 0
|
70
64
|
end
|
71
65
|
|
72
66
|
def config_error
|
73
|
-
|
67
|
+
"Model Configuration: no config directory in repo"
|
74
68
|
end
|
75
69
|
|
76
70
|
def model_file_error
|
@@ -78,12 +72,14 @@ module DataGuru
|
|
78
72
|
end
|
79
73
|
|
80
74
|
def model_attributes_error
|
81
|
-
"Model Configuration: no permitted attributes for model -
|
75
|
+
"Model Configuration: no permitted attributes for model - " \
|
76
|
+
"#{missing_model_contents.join(', ')}"
|
82
77
|
end
|
83
78
|
|
84
79
|
def model_attribute_name_error
|
85
80
|
reserved_model_attributes.map do |model, attrs|
|
86
|
-
"Model Configuration: reserved words used as attributes in model #{model} -
|
81
|
+
"Model Configuration: reserved words used as attributes in model #{model} - " \
|
82
|
+
"#{attrs.join(', ')}"
|
87
83
|
end
|
88
84
|
end
|
89
85
|
|
@@ -98,7 +94,7 @@ module DataGuru
|
|
98
94
|
|
99
95
|
def missing_models
|
100
96
|
return model_names unless config_valid?
|
101
|
-
model_names.flat_map{ |name| config.include?(name) ? [] : name }
|
97
|
+
model_names.flat_map { |name| config.include?(name) ? [] : name }
|
102
98
|
end
|
103
99
|
|
104
100
|
def missing_model_contents
|
@@ -117,23 +113,22 @@ module DataGuru
|
|
117
113
|
end
|
118
114
|
|
119
115
|
def reserved_model_attributes
|
120
|
-
|
121
|
-
wrong_attrs = config[model].keys & RESERVED_WORDS
|
122
|
-
[ model, wrong_attrs ]
|
123
|
-
end
|
124
|
-
Hash[wrong_attributes]
|
116
|
+
present_models.each_with_object({}) { |name, h| h[name] = config[name].keys & RESERVED_WORDS }
|
125
117
|
end
|
126
118
|
|
127
119
|
def missing_model_attributes
|
128
|
-
all =
|
120
|
+
all = present_models.each_with_object({}) { |model, h| h[model] = config[model] }
|
129
121
|
missing = all.map do |model, attributes|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
[
|
122
|
+
attrs = attributes.each_with_object({}) do |(name, types), h|
|
123
|
+
h[name] = ATTRIBUTE_TYPES - types.keys
|
124
|
+
end
|
125
|
+
without_empty = attrs.each_with_object({}) do |(name, types), h|
|
126
|
+
h[name] = types unless types.empty?
|
135
127
|
end
|
136
|
-
|
128
|
+
[model, without_empty]
|
129
|
+
end
|
130
|
+
missing.each_with_object({}) { |(model, without_empty), h| h[model] = without_empty }
|
131
|
+
.reject { |_k, v| v.empty? }
|
137
132
|
end
|
138
133
|
end
|
139
134
|
end
|
data/lib/data_guru/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_guru
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Nowak
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-
|
13
|
+
date: 2016-02-18 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -138,6 +138,34 @@ dependencies:
|
|
138
138
|
- - ">="
|
139
139
|
- !ruby/object:Gem::Version
|
140
140
|
version: '0'
|
141
|
+
- !ruby/object:Gem::Dependency
|
142
|
+
name: guard-rspec
|
143
|
+
requirement: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
type: :development
|
149
|
+
prerelease: false
|
150
|
+
version_requirements: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '0'
|
155
|
+
- !ruby/object:Gem::Dependency
|
156
|
+
name: guard-rubocop
|
157
|
+
requirement: !ruby/object:Gem::Requirement
|
158
|
+
requirements:
|
159
|
+
- - ">="
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: '0'
|
162
|
+
type: :development
|
163
|
+
prerelease: false
|
164
|
+
version_requirements: !ruby/object:Gem::Requirement
|
165
|
+
requirements:
|
166
|
+
- - ">="
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '0'
|
141
169
|
description:
|
142
170
|
email:
|
143
171
|
- adam.nowak@netguru.co
|
@@ -151,9 +179,14 @@ files:
|
|
151
179
|
- ".rspec"
|
152
180
|
- ".rubocop.yml"
|
153
181
|
- Gemfile
|
182
|
+
- Guardfile
|
154
183
|
- README.md
|
155
184
|
- Rakefile
|
185
|
+
- bin/_guard-core
|
156
186
|
- bin/console
|
187
|
+
- bin/guard
|
188
|
+
- bin/rspec
|
189
|
+
- bin/rubocop
|
157
190
|
- bin/setup
|
158
191
|
- circle.yml
|
159
192
|
- data_guru.gemspec
|
@@ -161,6 +194,8 @@ files:
|
|
161
194
|
- lib/data_guru/client.rb
|
162
195
|
- lib/data_guru/collection.rb
|
163
196
|
- lib/data_guru/configuration.rb
|
197
|
+
- lib/data_guru/exceptions.rb
|
198
|
+
- lib/data_guru/invalid_values.rb
|
164
199
|
- lib/data_guru/model.rb
|
165
200
|
- lib/data_guru/model_configuration.rb
|
166
201
|
- lib/data_guru/validation.rb
|