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 =
'1.0.2'.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
49 50 51 |
# File 'lib/jbuilder/jpartial.rb', line 49 def self.configure yield Template.new end |
.dangerous_method_name?(name) ⇒ Boolean
43 44 45 46 47 |
# File 'lib/jbuilder/jpartial.rb', line 43 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
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/jbuilder/jpartial.rb', line 31 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 |