Module: Served::Resource::Attributable::ClassMethods

Defined in:
lib/served/resource/attributable.rb

Defined Under Namespace

Modules: Prepend

Instance Method Summary collapse

Instance Method Details

#attribute(name, options = {}) ⇒ Object

declare an attribute for the resource

Examples:

class SomeResource
  attribute :attr1
end

Parameters:

  • name (Symbol)

    the name of the attribute



20
21
22
23
24
# File 'lib/served/resource/attributable.rb', line 20

def attribute(name, options = {})
  return if attributes.include?(name)
  attributes[name] = options
  attr_accessor name
end

#attributes(*args) ⇒ Hash

declare a set of attributes by name

Examples:

class SomeResource
  attributes :attr1, :attr2
end

Parameters:

  • *attributes (Array)

    a list of attributes for the resource

Returns:

  • (Hash)

    declared attributes for the resources



35
36
37
38
# File 'lib/served/resource/attributable.rb', line 35

def attributes(*args)
  args.each { |a| attribute a } unless args.empty?
  @attributes ||= {}
end