Module: Croods::Resource::Attributes
- Includes:
- Base
- Defined in:
- lib/croods/resource/attributes.rb,
lib/croods/resource/attributes/base.rb,
lib/croods/resource/attributes/request.rb,
lib/croods/resource/attributes/response.rb
Defined Under Namespace
Modules: Base
Classes: Request, Response
Instance Method Summary
collapse
Methods included from Base
#add_attribute, #additional_attributes, #ignored_attributes, #skip_attributes
Instance Method Details
#attribute_names ⇒ Object
46
47
48
|
# File 'lib/croods/resource/attributes.rb', line 46
def attribute_names
attributes.map { |key, _| key }
end
|
#attributes ⇒ Object
42
43
44
|
# File 'lib/croods/resource/attributes.rb', line 42
def attributes
merged_attributes(self, model.columns_hash)
end
|
#definitions ⇒ Object
50
51
52
53
54
|
# File 'lib/croods/resource/attributes.rb', line 50
def definitions
attributes
.merge(request_instance.additional_attributes)
.merge(response_instance.additional_attributes)
end
|
#merged_attributes(type, hash = nil) ⇒ Object
28
29
30
31
32
|
# File 'lib/croods/resource/attributes.rb', line 28
def merged_attributes(type, hash = nil)
(hash || attributes)
.merge(type.additional_attributes)
.reject { |name| type.ignored_attributes.include?(name) }
end
|
#request(&block) ⇒ Object
12
13
14
|
# File 'lib/croods/resource/attributes.rb', line 12
def request(&block)
request_instance.instance_eval(&block)
end
|
#request_attributes ⇒ Object
34
35
36
|
# File 'lib/croods/resource/attributes.rb', line 34
def request_attributes
merged_attributes(request_instance)
end
|
#request_instance ⇒ Object
20
21
22
|
# File 'lib/croods/resource/attributes.rb', line 20
def request_instance
@request_instance ||= Request.new(ignore_user: user_is_the_owner?)
end
|
#response(&block) ⇒ Object
16
17
18
|
# File 'lib/croods/resource/attributes.rb', line 16
def response(&block)
response_instance.instance_eval(&block)
end
|
#response_attributes ⇒ Object
38
39
40
|
# File 'lib/croods/resource/attributes.rb', line 38
def response_attributes
merged_attributes(response_instance)
end
|
#response_instance ⇒ Object
24
25
26
|
# File 'lib/croods/resource/attributes.rb', line 24
def response_instance
@response_instance ||= Response.new
end
|