Sha256: 1c93d018e0177033b5fa85ac57095816af335a9f31060d873b8a98806c259e55
Contents?: true
Size: 1.06 KB
Versions: 2
Compression:
Stored size: 1.06 KB
Contents
require 'sinclair' module Azeroth module Resourceable class Builder attr_reader :clazz, :model delegate :build, :add_method, to: :builder def initialize(clazz, model_name, **_options) @clazz = clazz @model = Azeroth::Model.new(model_name) add_params add_resource add_resource_for_routes add_routes end private def builder @builder ||= Sinclair.new(clazz) end def add_params add_method("#{model.name}_id", 'params.require(:id)') add_method("#{model.name}_params", "params.require(:#{model.name}).permit(:#{permitted_attributes.join(', :')})") end def add_resource ResourceBuilder.new(model, builder).append end def add_resource_for_routes ResourceRouteBuilder.new(model, builder).append end def add_routes RoutesBuilder.new(model, builder).append end def permitted_attributes @permitted_attributes ||= model.klass.attribute_names - ['id'] end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
azeroth-0.0.4 | lib/azeroth/resourceable/builder.rb |
azeroth-0.0.3 | lib/azeroth/resourceable/builder.rb |