Sha256: 0ba548ac6ff8c417d34052ffa87dd338bd23a83cfba65826c64e63f6617c95d6
Contents?: true
Size: 997 Bytes
Versions: 13
Compression:
Stored size: 997 Bytes
Contents
module FunWithJsonApi class Attribute attr_reader :name attr_reader :as attr_reader :options 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 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 def call(value) value end def sanitize_attribute_method :"parse_#{param_value}" end def param_value as end end end # Load pre-defined Attributes Dir["#{File.dirname(__FILE__)}/attributes/**/*.rb"].each { |f| require f }
Version data entries
13 entries across 13 versions & 1 rubygems