lib/xpose/controller.rb in xpose-0.1.5 vs lib/xpose/controller.rb in xpose-0.1.6

- old
+ new

@@ -3,39 +3,34 @@ 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) + @@exposed ||= {} + @@exposed[inst.conf.name] = inst + define_method inst.conf.name do + if instance_variable_defined?(inst.conf.ivar_name) + instance_variable_get(inst.conf.ivar_name) else - instance_variable_set(inst.conf.instance_variable_name, inst.call(self)) + instance_variable_set(inst.conf.ivar_name, inst.exposed_value(self)) end end - helper_method(inst.conf.method_name) - self._decorate(args) if inst.conf[:decorate] + helper_method(inst.conf.name) end end - def expose(name, value = nil, **args, &block) + def expose(names, value = nil, **args, &block) value = value || args.fetch(:value, nil) || block - _expose({ name: name, value: value }.merge(args)) + [names].flatten.each { |name| _expose({ name: name, value: value }.merge(args)) } end - def expose!(name, value = nil, **args, &block) + def expose!(names, value = nil, **args, &block) expose(name, value, args, &block) - before_action(name) + [names].flatten.each { |name| 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)) + def exposed + @@exposed ||= {} end end end end