class FunWithJsonApi::Attribute

Attributes

as[R]
name[R]
options[R]

Public Class Methods

create(name, options = {}) click to toggle source
# File lib/fun_with_json_api/attribute.rb, line 7
def self.create(name, options = {})
  format = options.fetch(:format, 'string')
  attribute_class_name = "#{format.to_s.classify}Attribute"
  if FunWithJsonApi::Attributes.const_defined?(attribute_class_name)
    FunWithJsonApi::Attributes.const_get(attribute_class_name)
  else
    raise ArgumentError, "Unknown attribute type: #{format}"
  end.new(name, options)
end
new(name, options = {}) click to toggle source
# File lib/fun_with_json_api/attribute.rb, line 17
def initialize(name, options = {})
  raise ArgumentError, 'name cannot be blank!' unless name.present?

  @name = name.to_sym
  @as = options.fetch(:as, name).to_sym
  @options = options
end

Public Instance Methods

call(value)
Alias for: decode
decode(value) click to toggle source
# File lib/fun_with_json_api/attribute.rb, line 25
def decode(value)
  value
end
Also aliased as: call
param_value() click to toggle source
# File lib/fun_with_json_api/attribute.rb, line 34
def param_value
  as
end
sanitize_attribute_method() click to toggle source
# File lib/fun_with_json_api/attribute.rb, line 30
def sanitize_attribute_method
  :"parse_#{param_value}"
end