Module: Neuron::Schema::Common
- Included in:
- Ad, AdZone, BlockedReferer, BlockedUserAgent, Event, GeoTarget, Pixel, Report, S3File, Zone
- Defined in:
- lib/neuron-client/schema/common.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #choice_of(choices, overrides = {}) ⇒ Object
- #datetime(overrides = {}) ⇒ Object
- #errors ⇒ Object
- #id(overrides = {}) ⇒ Object
- #integer(overrides = {}) ⇒ Object
- #merged(*hashes) ⇒ Object
- #missing_or_null ⇒ Object
- #missing_or_null_or_empty_hash ⇒ Object
- #nonnull_string(overrides = {}) ⇒ Object
- #null ⇒ Object
- #nullable_string(overrides = {}) ⇒ Object
- #object_type(name, properties) ⇒ Object
- #object_type_or_null(name, properties) ⇒ Object
- #one_of(*schemas) ⇒ Object
- #parameters(parameters, overrides = {}) ⇒ Object
- #priority(overrides = {}) ⇒ Object
- #set_of(schema, overrides = {}) ⇒ Object
- #slug(overrides = {}) ⇒ Object
- #timezone(overrides = {}) ⇒ Object
- #url(overrides = {}) ⇒ Object
- #uuid(overrides = {}) ⇒ Object
- #weight(overrides = {}) ⇒ Object
- #yes_no(overrides = {}) ⇒ Object
Class Method Details
.included(base) ⇒ Object
21 22 23 |
# File 'lib/neuron-client/schema/common.rb', line 21 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#choice_of(choices, overrides = {}) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/neuron-client/schema/common.rb', line 53 def choice_of(choices, overrides={}) merged({ :type => "string", :enum => choices, :required => true }, overrides) end |
#datetime(overrides = {}) ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'lib/neuron-client/schema/common.rb', line 75 def datetime(overrides={}) merged({ :type => "string", :format => "date-time", :pattern => "^\\d{4}-[01]?\\d-[0-3]?\\dT[012]?\\d:[0-5]?\\d:[0-5]?\\dZ$", :required => true }, overrides) end |
#errors ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/neuron-client/schema/common.rb', line 84 def errors merged({ :type => "object", :required => true, :additionalProperties => { :type => "array", :minItems => 1, :items => { :type => "string", :required => true } } }, {}) end |
#id(overrides = {}) ⇒ Object
99 100 101 102 103 104 105 |
# File 'lib/neuron-client/schema/common.rb', line 99 def id(overrides={}) merged({ :type => %w(integer string), :required => true, :pattern => "^\\d+$" }, overrides) end |
#integer(overrides = {}) ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/neuron-client/schema/common.rb', line 107 def integer(overrides={}) merged({ :type => %w(integer string), :required => true, :pattern => "^\\-?\\d+$" }, overrides) end |
#merged(*hashes) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/neuron-client/schema/common.rb', line 45 def merged(*hashes) result = Map.new hashes.each do |hash| result = ::DeepMerge::deep_merge!(hash, result, {:preserve_unmergeables => false}) end result end |
#missing_or_null ⇒ Object
115 116 117 118 119 120 |
# File 'lib/neuron-client/schema/common.rb', line 115 def missing_or_null merged({ :type => "null", :required => false }, {}) end |
#missing_or_null_or_empty_hash ⇒ Object
122 123 124 125 126 127 128 |
# File 'lib/neuron-client/schema/common.rb', line 122 def missing_or_null_or_empty_hash merged({ :type => %w(object null), :additionalProperties => false, :required => false }, {}) end |
#nonnull_string(overrides = {}) ⇒ Object
130 131 132 133 134 135 136 |
# File 'lib/neuron-client/schema/common.rb', line 130 def nonnull_string(overrides={}) merged({ :type => "string", :maxLength => 255, :required => "true" }, overrides) end |
#null ⇒ Object
138 139 140 141 142 143 |
# File 'lib/neuron-client/schema/common.rb', line 138 def null merged({ :type => "null", :required => true }, {}) end |
#nullable_string(overrides = {}) ⇒ Object
145 146 147 148 149 150 151 |
# File 'lib/neuron-client/schema/common.rb', line 145 def nullable_string(overrides={}) merged({ :type => %w(string null), :maxLength => 255, :required => true }, overrides) end |
#object_type(name, properties) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/neuron-client/schema/common.rb', line 25 def object_type(name, properties) Map.new( :type => "object", :additionalProperties => false, :required => true, :properties => { name => { :type => "object", :required => true, :additionalProperties => false, :properties => properties } } ) end |
#object_type_or_null(name, properties) ⇒ Object
41 42 43 |
# File 'lib/neuron-client/schema/common.rb', line 41 def object_type_or_null(name, properties) merged(object_type(name, properties), {:properties => {name => {:type => %w(object null)}}}) end |
#one_of(*schemas) ⇒ Object
61 62 63 |
# File 'lib/neuron-client/schema/common.rb', line 61 def one_of(*schemas) merged({:type => schemas}, {}) end |
#parameters(parameters, overrides = {}) ⇒ Object
153 154 155 156 157 158 159 160 |
# File 'lib/neuron-client/schema/common.rb', line 153 def parameters(parameters, overrides={}) merged({ :type => "object", :required => true, :additionalProperties => false, :properties => parameters }, overrides) end |
#priority(overrides = {}) ⇒ Object
162 163 164 165 166 167 168 169 170 |
# File 'lib/neuron-client/schema/common.rb', line 162 def priority(overrides={}) merged({ :type => %w(integer string), :required => true, :minimum => 1, :maximum => 10, :enum => (1..10).to_a + (1..10).map(&:to_s) }, overrides) end |
#set_of(schema, overrides = {}) ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/neuron-client/schema/common.rb', line 65 def set_of(schema, overrides={}) merged({ :type => "array", :additionalItems => false, :uniqueItems => true, :required => true, :items => schema }, overrides) end |
#slug(overrides = {}) ⇒ Object
172 173 174 175 176 177 178 179 180 |
# File 'lib/neuron-client/schema/common.rb', line 172 def slug(overrides={}) merged({ :type => "string", :required => true, :pattern => "^\\w+$", :maxLength => 255, :minLength => 1 }, overrides) end |
#timezone(overrides = {}) ⇒ Object
182 183 184 |
# File 'lib/neuron-client/schema/common.rb', line 182 def timezone(overrides={}) choice_of(Neuron::Client::Ad::TIME_ZONES, overrides) end |
#url(overrides = {}) ⇒ Object
186 187 188 189 190 191 192 193 194 |
# File 'lib/neuron-client/schema/common.rb', line 186 def url(overrides={}) merged({ :type => "string", :format => "uri", :pattern => "^https?:\/\/", :maxLength => 2000, :required => true }, overrides) end |
#uuid(overrides = {}) ⇒ Object
196 197 198 199 200 201 202 203 |
# File 'lib/neuron-client/schema/common.rb', line 196 def uuid(overrides={}) merged({ :type => "string", :pattern => "^[a-z0-9]+$", :maxlength => 25, :required => true }, overrides) end |
#weight(overrides = {}) ⇒ Object
205 206 207 208 209 210 211 212 213 |
# File 'lib/neuron-client/schema/common.rb', line 205 def weight(overrides={}) merged({ :type => %w(number string), :required => true, :minimum => -1000, :maximum => 1000, :pattern => "^\\-?\\d+(\\.\\d+)?$" }, overrides) end |
#yes_no(overrides = {}) ⇒ Object
215 216 217 |
# File 'lib/neuron-client/schema/common.rb', line 215 def yes_no(overrides={}) choice_of(%w(Yes No), overrides) end |