Module: Jbuilder::Jpartial
- Defined in:
- lib/jbuilder/jpartial.rb,
lib/jbuilder/jpartial/railtie.rb,
lib/jbuilder/jpartial/version.rb
Overview
Jpartial module
Defined Under Namespace
Classes: JpartialHandler, Railtie
Constant Summary collapse
- DangerousMethodName =
Class.new(ArgumentError)
- Template =
Proxy object that sends all method calls to Jpartial.jpartial
Class.new(begin require 'active_support/proxy_object' ActiveSupport::ProxyObject rescue LoadError require 'active_support/basic_object' ActiveSupport::BasicObject end) do def method_missing(name, *args, &block) name = name.to_s == 'send' ? args.first.to_sym : name Jpartial.jpartial(name, &block) end end
- VERSION =
'0.2.0'.freeze
Class Method Summary collapse
- .configure {|Template.new| ... } ⇒ Object
- .dangerous_method_name?(name) ⇒ Boolean
- .jpartial(name, &block) ⇒ Object
Class Method Details
.configure {|Template.new| ... } ⇒ Object
33 34 35 |
# File 'lib/jbuilder/jpartial.rb', line 33 def self.configure yield Template.new end |
.dangerous_method_name?(name) ⇒ Boolean
27 28 29 30 31 |
# File 'lib/jbuilder/jpartial.rb', line 27 def self.dangerous_method_name?(name) !@defined_by_user.include?(name) && Jbuilder.method_defined?(name) || Jbuilder.private_method_defined?(name) end |
.jpartial(name, &block) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/jbuilder/jpartial.rb', line 15 def self.jpartial(name, &block) if dangerous_method_name?(name) raise DangerousMethodName, "The method `##{name}` is already defined"\ ' by Jbuilder. Please choose another name to define your partial' else Jbuilder.class_eval do define_method(name, &block) end @defined_by_user << name unless @defined_by_user.include?(name) end end |