Module: CFoundry::V2::ModelMagic

Includes:
Attribute, ClientExtensions, HasSummary, QueryableBy, ToMany, ToOne
Included in:
Model
Defined in:
lib/cfoundry/v2/model_magic.rb,
lib/cfoundry/v2/model_magic/to_one.rb,
lib/cfoundry/v2/model_magic/to_many.rb,
lib/cfoundry/v2/model_magic/attribute.rb,
lib/cfoundry/v2/model_magic/has_summary.rb,
lib/cfoundry/v2/model_magic/client_extensions.rb

Defined Under Namespace

Modules: Attribute, ClientExtensions, HasSummary, QueryableBy, ToMany, ToOne

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from QueryableBy

#queryable_by

Methods included from ToMany

#to_many

Methods included from ToOne

#to_one

Methods included from Attribute

#attribute

Methods included from HasSummary

#has_summary

Methods included from ClientExtensions

#add_client_methods

Instance Attribute Details

#scoped_organizationObject (readonly)

Returns the value of attribute scoped_organization.



31
32
33
# File 'lib/cfoundry/v2/model_magic.rb', line 31

def scoped_organization
  @scoped_organization
end

#scoped_spaceObject (readonly)

Returns the value of attribute scoped_space.



31
32
33
# File 'lib/cfoundry/v2/model_magic.rb', line 31

def scoped_space
  @scoped_space
end

Class Method Details

.params_from(args) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/cfoundry/v2/model_magic.rb', line 73

def self.params_from(args)
  options, _ = args
  options ||= {}
  options[:depth] ||= 1

  params = {}
  options.each do |k, v|
    case k
    when :depth
      params[:"inline-relations-depth"] = v
    when :query
      params[:q] = v.join(":")
    end
  end

  params
end

Instance Method Details

#attributesObject



48
49
50
# File 'lib/cfoundry/v2/model_magic.rb', line 48

def attributes
  @attributes ||= {}
end

#defaultsObject



44
45
46
# File 'lib/cfoundry/v2/model_magic.rb', line 44

def defaults
  @defaults ||= {}
end

#inherited(klass) ⇒ Object



60
61
62
63
# File 'lib/cfoundry/v2/model_magic.rb', line 60

def inherited(klass)
  add_client_methods(klass)
  has_summary
end

#object_nameObject



33
34
35
36
37
38
# File 'lib/cfoundry/v2/model_magic.rb', line 33

def object_name
  @object_name ||=
    name.split("::").last.gsub(
      /([a-z])([A-Z])/,
      '\1_\2').downcase.to_sym
end

#plural_object_nameObject



40
41
42
# File 'lib/cfoundry/v2/model_magic.rb', line 40

def plural_object_name
  :"#{object_name}s"
end

#scoped_to_organization(relation = :organization) ⇒ Object



65
66
67
# File 'lib/cfoundry/v2/model_magic.rb', line 65

def scoped_to_organization(relation = :organization)
  @scoped_organization = relation
end

#scoped_to_space(relation = :space) ⇒ Object



69
70
71
# File 'lib/cfoundry/v2/model_magic.rb', line 69

def scoped_to_space(relation = :space)
  @scoped_space = relation
end

#to_many_relationsObject



56
57
58
# File 'lib/cfoundry/v2/model_magic.rb', line 56

def to_many_relations
  @to_many_relations ||= {}
end

#to_one_relationsObject



52
53
54
# File 'lib/cfoundry/v2/model_magic.rb', line 52

def to_one_relations
  @to_one_relations ||= {}
end