Class: SBF::Client::TopLevelEntity
Direct Known Subclasses
Batch, Campaign, Challenge, Challenger, Config, Contact, ContactGroup, Disease, DocumentLibrary, DocumentLibraryCategory, Donation, Donor, Event, EventApplication, EventDonationSummary, EventParticipantSummary, EventSupporter, Fund, Fundraiser, Grant, Institution, InternationalPartner, Kid, KidHonor, KidInstitution, MatchingGift::Company, Memorial, Message, NewsletterRecipient, Organization, Page, Participant, Person, Photo, RecurringGift, Search, Section, ShaveSchedule, Summary, Team, User
Constant Summary
collapse
- DEFAULT_ENDPOINT =
SBF::Client::EntityEndpoint
- DEFAULT_INSTANCE_ACTIONS =
[:save, :create, :update, :delete]
- DEFAULT_CLASS_ACTIONS =
[:get, :find, :find_first, :aggregate, :update, :delete]
- DEFAULT_CRUD_ACTIONS =
DEFAULT_INSTANCE_ACTIONS + DEFAULT_CLASS_ACTIONS
Constants inherited
from BaseEntity
BaseEntity::ELSE
Instance Attribute Summary
Attributes inherited from BaseEntity
#errors
Class Method Summary
collapse
Instance Method Summary
collapse
#cache_id, included
Methods inherited from BaseEntity
allow_instantiation?, attr_accessor, attr_reader, attr_writer, attributes, collection_attributes, #destroyed?, #dirty_data, entity_attr_accessor, entity_attr_reader, entity_attr_writer, entity_attributes, entity_collection_attr_accessor, entity_collection_attr_reader, entity_collection_attr_writer, #error, inherited, #initialize, #keys_hash, #model_name, multitype_attr_accessor, multitype_attr_reader, multitype_attr_writer, multitype_collection_attr_accessor, multitype_collection_attr_reader, multitype_collection_attr_writer, #not_provided_attributes, optional_attributes, #persisted?, #reload!, #reload_recursive, #rollback!, #to_hash, #to_json
#add_errors, #data, #error?, #errors?, #errors_http_code=, #http_code, #success?
Class Method Details
._endpoint ⇒ Object
27
28
29
|
# File 'lib/stbaldricks/entities/lib/top_level.rb', line 27
def _endpoint
DEFAULT_ENDPOINT.new(self)
end
|
.action(name) ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/stbaldricks/entities/lib/top_level.rb', line 59
def action(name)
instance_action(name) if [:save, :create].include?(name)
if name == :update
define_method(name) do |*args|
result = endpoint.update(id, self, *args)
result unless result.is_a?(SBF::Client::TopLevelEntity)
result.errors? ? false : result
end
end
if name == :delete
define_method(:delete) do |*_args|
response = endpoint.delete(id)
if response.error?
add_errors(response.error)
errors.instance_variable_set(:@http_code, response.http_code)
false
else
@destroyed = true
freeze
end
end
end
class_action(name)
end
|
.actions(actions) ⇒ Object
39
40
41
|
# File 'lib/stbaldricks/entities/lib/top_level.rb', line 39
def actions(actions)
actions.each { |m| action(m) }
end
|
.blacklist_action(name) ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/stbaldricks/entities/lib/top_level.rb', line 87
def blacklist_action(name)
define_method(name) do |*_|
raise NoMethodError.new("#{name} is blacklisted", name)
end
singleton_class.class_eval do
define_method(name) do |*_|
raise NoMethodError.new("#{name} is blacklisted", name)
end
end
end
|
.class_action(name) ⇒ Object
51
52
53
54
55
56
57
|
# File 'lib/stbaldricks/entities/lib/top_level.rb', line 51
def class_action(name)
singleton_class.class_eval do
define_method(name) do |*args|
endpoint.send(name, *args)
end
end
end
|
.define_endpoint(mod, options) ⇒ Object
31
32
33
34
35
36
37
|
# File 'lib/stbaldricks/entities/lib/top_level.rb', line 31
def define_endpoint(mod, options)
singleton_class.class_eval do
define_method(:_endpoint) do
@_endpoint ||= mod.new(options.fetch(:target_class, self))
end
end
end
|
.endpoint(mod = nil, options = {}) ⇒ Object
22
23
24
25
|
# File 'lib/stbaldricks/entities/lib/top_level.rb', line 22
def endpoint(mod = nil, options = {})
return define_endpoint(mod, options) if mod
_endpoint
end
|
.instance_action(name) ⇒ Object
43
44
45
46
47
48
49
|
# File 'lib/stbaldricks/entities/lib/top_level.rb', line 43
def instance_action(name)
define_method(name) do |*args|
result = endpoint.send(name, self, *args)
result unless result.is_a?(SBF::Client::TopLevelEntity)
[:save, :create].include?(name) && result.errors? ? false : result
end
end
|
Instance Method Details
#endpoint ⇒ Object
106
107
108
|
# File 'lib/stbaldricks/entities/lib/top_level.rb', line 106
def endpoint
self.class.endpoint
end
|