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
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 130
def method_missing(name_as_symbol, *args, &block)
name = normalize_accessor name_as_symbol
return data if name_as_symbol == :_raw_data!
if name.end_with?('=')
if patchable_fields.include?(name[0..-2])
dirty_data[name[0..-2]] = args[0]
return
end
super
end
return data[name[0..2]] if name.end_with?('!') && data.key?(name[0..-2])
return objectify(name) if object_fields.include? name
return arrayify(name, array_object_fields[name]) if array_object_fields.key?(name)
return dirty_data[name] if dirty_data.key?(name)
return data[name] if data.is_a?(Hash) && data.key?(name)
super
end
|
Class Method Details
.included(other_klass) ⇒ Object
9
10
11
|
# File 'lib/cloudflair/entity.rb', line 9
def self.included(other_klass)
other_klass.extend ClassMethods
end
|
Instance Method Details
#data=(data) ⇒ Object
:internal: Used to pre-populate an entity
170
171
172
|
# File 'lib/cloudflair/entity.rb', line 170
def data=(data)
@data = data
end
|
#delete ⇒ Object
108
109
110
111
112
113
114
115
116
|
# File 'lib/cloudflair/entity.rb', line 108
def delete
raise 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
100
101
102
103
104
105
106
|
# File 'lib/cloudflair/entity.rb', line 100
def patch
return self if dirty_data.empty?
@data = response connection.patch path, dirty_data
revert
self
end
|
#reload ⇒ Object
Also known as:
get!
94
95
96
97
98
|
# File 'lib/cloudflair/entity.rb', line 94
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
|
# File 'lib/cloudflair/entity.rb', line 154
def respond_to_missing?(name_as_symbol, *args)
name = normalize_accessor name_as_symbol
return true if name_as_symbol == :_raw_data!
return true if name.end_with?('=') && patchable_fields.include?(name[0..-2])
return true if name.end_with?('!') && data.key?(name[0..-2])
return true if object_fields.include? name
return true if array_object_fields.key?(name)
return true if dirty_data.key?(name)
return true if data.is_a?(Hash) && data.key?(name)
super
end
|
#revert ⇒ Object
90
91
92
|
# File 'lib/cloudflair/entity.rb', line 90
def revert
dirty_data.clear
end
|
#update(updated_fields) ⇒ Object
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/cloudflair/entity.rb', line 118
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
|