bodhi-slam 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bodhi-slam.rb +32 -6
- data/lib/bodhi-slam/queries.rb +13 -8
- data/lib/bodhi-slam/resource.rb +1 -1
- data/lib/bodhi-slam/types.rb +7 -3
- data/lib/bodhi-slam/users.rb +28 -0
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d37d15d216eee1331997b6c36c8354c96f2a5cc8
|
4
|
+
data.tar.gz: 1f718df6ea9586e6af5f3b24c82b3d3a7a54af7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9dd80e02c44454dbb8abf5d813578186e4492fb43fe4bd76ddf60fff63e76f0674689d0cdbe301e5e77c3233ecff49d9a66eac3604eb53b5e73030bb562319ad
|
7
|
+
data.tar.gz: a1d883d59e1f0aae13bb8cdff2f86dfa8e30a4891d4bb4f5f872cd169b4de42fad77ae62b9a8627f7cc60a9535ec0d8eb29625c30102733dfcad13cd8c1d2835
|
data/lib/bodhi-slam.rb
CHANGED
@@ -1,15 +1,11 @@
|
|
1
|
+
require "json"
|
2
|
+
require "time"
|
1
3
|
require 'faraday'
|
2
4
|
require 'faraday_middleware'
|
3
5
|
require 'net/http/persistent'
|
4
|
-
|
5
|
-
require "json"
|
6
|
-
require "time"
|
7
|
-
require "SecureRandom"
|
8
6
|
require 'regexp-examples'
|
9
|
-
require 'active_model'
|
10
7
|
|
11
8
|
require 'bodhi-slam/support'
|
12
|
-
|
13
9
|
require 'bodhi-slam/validations'
|
14
10
|
require 'bodhi-slam/errors'
|
15
11
|
require 'bodhi-slam/context'
|
@@ -42,11 +38,41 @@ class BodhiSlam
|
|
42
38
|
yield bodhi_context
|
43
39
|
end
|
44
40
|
|
41
|
+
def self.define_resources(context, options={})
|
42
|
+
# symbolize keys for the options hash
|
43
|
+
options = options.reduce({}) do |memo, (k, v)|
|
44
|
+
memo.merge({ k.to_sym => v})
|
45
|
+
end
|
46
|
+
|
47
|
+
if context.invalid?
|
48
|
+
raise Bodhi::ContextErrors.new(context.errors.messages), context.errors.to_a.to_s
|
49
|
+
end
|
50
|
+
|
51
|
+
enumerations = Bodhi::Enumeration.find_all(context)
|
52
|
+
|
53
|
+
if options[:include].is_a? Array
|
54
|
+
types = Bodhi::Type.where("{name: { $in: #{options[:include].map(&:to_s)} }}").from(context).all
|
55
|
+
elsif options[:except].is_a? Array
|
56
|
+
types = Bodhi::Type.where("{name: { $nin: #{options[:except].map(&:to_s)} }}").from(context).all
|
57
|
+
else
|
58
|
+
types = Bodhi::Type.find_all(context)
|
59
|
+
end
|
60
|
+
|
61
|
+
types.collect do |type|
|
62
|
+
begin
|
63
|
+
Bodhi::Type.create_class_with(type)
|
64
|
+
rescue Exception => error
|
65
|
+
puts "WARNING: Unable to create class for #{type.name}. The following error was encountered: #{error}"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
45
70
|
# Dynamically creates Ruby Classes for each type in the given +context+
|
46
71
|
#
|
47
72
|
# context = Bodhi::Context.new(valid_params)
|
48
73
|
# BodhiSlam.analyze(context) # => [#<Class:0x007fbff403e808 @name="TestType">, #<Class:0x007fbff403e808 @name="TestType2">, ...]
|
49
74
|
def self.analyze(context)
|
75
|
+
puts "WARNING: The method BodhiSlam.analyze(context) has been depreciated and will be removed by version 1.0"
|
50
76
|
if context.invalid?
|
51
77
|
raise Bodhi::ContextErrors.new(context.errors.messages), context.errors.to_a.to_s
|
52
78
|
end
|
data/lib/bodhi-slam/queries.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
module Bodhi
|
2
2
|
class Query
|
3
|
-
attr_reader :klass, :url, :context, :criteria, :fields, :paging, :sorting
|
3
|
+
attr_reader :klass, :controller, :url, :context, :criteria, :fields, :paging, :sorting
|
4
4
|
|
5
|
-
def initialize(klass)
|
5
|
+
def initialize(klass, controller="resources")
|
6
|
+
@controller = controller
|
6
7
|
@klass = Object.const_get(klass.to_s)
|
7
8
|
@criteria = []
|
8
9
|
@fields = []
|
@@ -20,9 +21,13 @@ module Bodhi
|
|
20
21
|
|
21
22
|
def url
|
22
23
|
unless context.nil?
|
23
|
-
|
24
|
+
if @controller == "resources"
|
25
|
+
query = "/#{context.namespace}/#{controller}/#{klass}?"
|
26
|
+
else
|
27
|
+
query = "/#{context.namespace}/#{controller}?"
|
28
|
+
end
|
24
29
|
else
|
25
|
-
query = "
|
30
|
+
query = "/#{controller}/#{klass}?"
|
26
31
|
end
|
27
32
|
params = []
|
28
33
|
|
@@ -69,7 +74,7 @@ module Bodhi
|
|
69
74
|
end
|
70
75
|
|
71
76
|
query << params.join('&')
|
72
|
-
query.gsub(/\s+/, "")
|
77
|
+
#query.gsub(/\s+/, "")
|
73
78
|
end
|
74
79
|
|
75
80
|
def all
|
@@ -90,7 +95,7 @@ module Bodhi
|
|
90
95
|
raise Bodhi::ApiErrors.new(body: result.body, status: result.status), "status: #{result.status}, body: #{result.body}"
|
91
96
|
end
|
92
97
|
|
93
|
-
result.body.map{ |attributes| klass.new(attributes) }
|
98
|
+
result.body.map{ |attributes| klass.new(attributes.merge(bodhi_context: context)) }
|
94
99
|
end
|
95
100
|
|
96
101
|
def first
|
@@ -111,7 +116,7 @@ module Bodhi
|
|
111
116
|
raise Bodhi::ApiErrors.new(body: result.body, status: result.status), "status: #{result.status}, body: #{result.body}"
|
112
117
|
end
|
113
118
|
|
114
|
-
result.body.map{ |attributes| klass.new(attributes) }.first
|
119
|
+
result.body.map{ |attributes| klass.new(attributes.merge(bodhi_context: context)) }.first
|
115
120
|
end
|
116
121
|
|
117
122
|
def last
|
@@ -132,7 +137,7 @@ module Bodhi
|
|
132
137
|
raise Bodhi::ApiErrors.new(body: result.body, status: result.status), "status: #{result.status}, body: #{result.body}"
|
133
138
|
end
|
134
139
|
|
135
|
-
result.body.map{ |attributes| klass.new(attributes) }.last
|
140
|
+
result.body.map{ |attributes| klass.new(attributes.merge(bodhi_context: context)) }.last
|
136
141
|
end
|
137
142
|
|
138
143
|
def from(context)
|
data/lib/bodhi-slam/resource.rb
CHANGED
@@ -366,7 +366,7 @@ module Bodhi
|
|
366
366
|
|
367
367
|
def self.included(base)
|
368
368
|
base.extend(ClassMethods)
|
369
|
-
base.include(InstanceMethods, Bodhi::Validations, Bodhi::Properties, Bodhi::Indexes, Bodhi::Factories
|
369
|
+
base.include(InstanceMethods, Bodhi::Validations, Bodhi::Properties, Bodhi::Indexes, Bodhi::Factories)
|
370
370
|
base.instance_variable_set(:@embedded, false)
|
371
371
|
end
|
372
372
|
end
|
data/lib/bodhi-slam/types.rb
CHANGED
@@ -139,6 +139,12 @@ module Bodhi
|
|
139
139
|
end
|
140
140
|
end
|
141
141
|
|
142
|
+
def self.where(query)
|
143
|
+
query_obj = Bodhi::Query.new(Bodhi::Type, "types")
|
144
|
+
query_obj.where(query)
|
145
|
+
query_obj
|
146
|
+
end
|
147
|
+
|
142
148
|
# Dynamically defines a new Ruby class for the given +type+
|
143
149
|
# Class validations, factory, and helper methods will also be added
|
144
150
|
#
|
@@ -164,9 +170,7 @@ module Bodhi
|
|
164
170
|
attr_properties.delete_if{ |key, value| [:trim, :unique, :default, :isCurrentUser, :toLower].include?(key) }
|
165
171
|
|
166
172
|
# Do not add factories or validations for system properties
|
167
|
-
|
168
|
-
klass.property attr_name
|
169
|
-
else
|
173
|
+
unless attr_properties[:system] == true
|
170
174
|
klass.field(attr_name, attr_properties)
|
171
175
|
end
|
172
176
|
end
|
data/lib/bodhi-slam/users.rb
CHANGED
@@ -88,6 +88,34 @@ module Bodhi
|
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
|
+
def update!(options)
|
92
|
+
update_attributes(options)
|
93
|
+
|
94
|
+
result = bodhi_context.connection.put do |request|
|
95
|
+
request.url "/#{bodhi_context.namespace}/users/#{username}"
|
96
|
+
request.headers['Content-Type'] = 'application/json'
|
97
|
+
request.headers[bodhi_context.credentials_header] = bodhi_context.credentials
|
98
|
+
request.body = attributes.to_json
|
99
|
+
end
|
100
|
+
|
101
|
+
if result.status != 204
|
102
|
+
raise Bodhi::ApiErrors.new(body: result.body, status: result.status), "status: #{result.status}, body: #{result.body}"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def patch!(options)
|
107
|
+
result = bodhi_context.connection.patch do |request|
|
108
|
+
request.url "/#{bodhi_context.namespace}/users/#{username}"
|
109
|
+
request.headers['Content-Type'] = 'application/json'
|
110
|
+
request.headers[bodhi_context.credentials_header] = bodhi_context.credentials
|
111
|
+
request.body = options.to_json
|
112
|
+
end
|
113
|
+
|
114
|
+
if result.status != 204
|
115
|
+
raise Bodhi::ApiErrors.new(body: result.body, status: result.status), "status: #{result.status}, body: #{result.body}"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
91
119
|
def delete!
|
92
120
|
result = bodhi_context.connection.delete do |request|
|
93
121
|
request.url "/#{bodhi_context.namespace}/users/#{username}"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bodhi-slam
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- willdavis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -80,20 +80,6 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '1.1'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: activemodel
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '4.2'
|
90
|
-
type: :runtime
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - "~>"
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '4.2'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: rspec
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|