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_namesObject



46
47
48
# File 'lib/croods/resource/attributes.rb', line 46

def attribute_names
  attributes.map { |key, _| key }
end

#attributesObject



42
43
44
# File 'lib/croods/resource/attributes.rb', line 42

def attributes
  merged_attributes(self, model.columns_hash)
end

#definitionsObject



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_attributesObject



34
35
36
# File 'lib/croods/resource/attributes.rb', line 34

def request_attributes
  merged_attributes(request_instance)
end

#request_instanceObject



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_attributesObject



38
39
40
# File 'lib/croods/resource/attributes.rb', line 38

def response_attributes
  merged_attributes(response_instance)
end

#response_instanceObject



24
25
26
# File 'lib/croods/resource/attributes.rb', line 24

def response_instance
  @response_instance ||= Response.new
end