Sha256: b8293bf30fd179ead7be59be59c9722cf17f4e13e3b7959046cda6b65eeb7452
Contents?: true
Size: 1.22 KB
Versions: 4
Compression:
Stored size: 1.22 KB
Contents
module Xpose module Controller extend ActiveSupport::Concern module ClassMethods def _expose(**args) ::Xpose::Exposed.new(args).tap do |inst| define_method inst.conf.method_name do if instance_variable_defined?(inst.conf.instance_variable_name) instance_variable_get(inst.conf.instance_variable_name) else instance_variable_set(inst.conf.instance_variable_name, inst.call(self)) end end helper_method(inst.conf.method_name) self._decorate(args) if inst.conf[:decorate] end end def expose(name, value = nil, **args, &block) value = value || args.fetch(:value, nil) || block _expose({ name: name, value: value }.merge(args)) end def expose!(name, value = nil, **args, &block) expose(name, value, args, &block) before_action(name) end def _decorate(**args) ::Xpose::Decorated.new(args).tap do |inst| _expose({ name: inst.conf.decorated_name, value: -> { inst.call(self) }, decorate: false }) end end def decorate(name, **args, &block) _decorate({ name: name }.merge(args)) end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
xpose-0.1.5 | lib/xpose/controller.rb |
xpose-0.1.2 | lib/xpose/controller.rb |
xpose-0.1.1 | lib/xpose/controller.rb |
xpose-0.1.0 | lib/xpose/controller.rb |