Module: Cloudflair::Entity
- Includes:
- Communication
- Included in:
- AdvancedDdos, AlwaysOnline, AvailablePlan, AvailableRatePlan, BrowserCacheTtl, BrowserCheck, CacheLevel, ChallengeTtl, CustomHostname, DevelopmentMode, DnsRecord, EmailObfuscation, HotlinkProtection, IpGeolocation, Ipv6, Minify, Mirage, MobileRedirect, OriginErrorPagePassThru, Polish, PrefetchPreload, Railgun, Railguns, ResponseBuffering, RocketLoader, SecurityHeader, SecurityLevel, ServerSideExclude, SortQueryStringForCache, Ssl, Tls12Only, Tls13, TlsClientAuth, TrueClientIpHeader, Waf, Websockets, Zone
- Defined in:
- lib/cloudflair/entity.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary
collapse
Instance Method Summary
collapse
#connection, #hash_to_object, #response
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name_as_symbol, *args, &block) ⇒ Object
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
# File 'lib/cloudflair/entity.rb', line 126
def method_missing(name_as_symbol, *args, &block)
name = normalize_accessor name_as_symbol
return data if :_raw_data! == name_as_symbol
if name.end_with?('=')
if patchable_fields.include?(name[0..-2])
dirty_data[name[0..-2]] = args[0]
return
else
super
end
end
if name.end_with?('!') && data.keys.include?(name[0..-2])
return data[name[0..2]]
end
return objectify(name) if object_fields.include? name
return arrayify(name, array_object_fields[name]) if array_object_fields.keys.include? name
return dirty_data[name] if dirty_data.keys.include? name
return data[name] if data.is_a?(Hash) && data.keys.include?(name)
super
end
|
Class Method Details
.included(other_klass) ⇒ Object
7
8
9
|
# File 'lib/cloudflair/entity.rb', line 7
def self.included(other_klass)
other_klass.extend ClassMethods
end
|
Instance Method Details
#data=(data) ⇒ Object
:internal: Used to pre-populate an entity
173
174
175
|
# File 'lib/cloudflair/entity.rb', line 173
def data=(data)
@data = data
end
|
#delete ⇒ Object
104
105
106
107
108
109
110
111
112
|
# File 'lib/cloudflair/entity.rb', line 104
def delete
fail Cloudflair::CloudflairError, "Can't delete unless deletable=true" unless deletable
return self if @deleted
@data = response connection.delete path
@deleted = true
revert
self
end
|
#patch ⇒ Object
Also known as:
save
96
97
98
99
100
101
102
|
# File 'lib/cloudflair/entity.rb', line 96
def patch
return self if dirty_data.empty?
@data = response connection.patch path, dirty_data
revert
self
end
|
#reload ⇒ Object
Also known as:
get!
90
91
92
93
94
|
# File 'lib/cloudflair/entity.rb', line 90
def reload
@data = get
revert
self
end
|
#respond_to_missing?(name_as_symbol, *args) ⇒ Boolean
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
# File 'lib/cloudflair/entity.rb', line 154
def respond_to_missing?(name_as_symbol, *args)
name = normalize_accessor name_as_symbol
return true if :_raw_data! == name_as_symbol
return true if name.end_with?('=') && patchable_fields.include?(name[0..-2])
return true if name.end_with?('!') && data.keys.include?(name[0..-2])
return true if object_fields.include? name
return true if array_object_fields.keys.include? name
return true if dirty_data.keys.include? name
return true if data.is_a?(Hash) && data.keys.include?(name)
super
end
|
#revert ⇒ Object
86
87
88
|
# File 'lib/cloudflair/entity.rb', line 86
def revert
dirty_data.clear
end
|
#update(updated_fields) ⇒ Object
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/cloudflair/entity.rb', line 114
def update(updated_fields)
checked_updated_fields = {}
updated_fields.each do |key, values|
s_key = normalize_accessor key
checked_updated_fields[s_key] = values if patchable_fields.include? s_key
end
dirty_data.merge! checked_updated_fields
patch
end
|