Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

use ActiveSupport::Concern for KP module

  • Loading branch information...
commit 9be3dc997aa5f0235254a68f063fc0d1c7d9fe0f 1 parent b0182a8
Georg Leciejewski schorsch authored
Showing with 9 additions and 11 deletions.
  1. +0 −1  king_placeholder.gemspec
  2. +9 −10 lib/king_placeholder.rb
1  king_placeholder.gemspec
View
@@ -16,7 +16,6 @@ Gem::Specification.new do |gem|
gem.version = KingPlaceholder::VERSION
gem.add_runtime_dependency 'statemachine'
- gem.add_runtime_dependency 'i18n'
gem.add_runtime_dependency 'activesupport'
gem.add_development_dependency 'activerecord'
19 lib/king_placeholder.rb
View
@@ -6,18 +6,17 @@
# A Placeholder can be used inside any text string and will be replaced with a
# stringified, formatted value(by KingViews gem => KingFormat::FormattingHelper.strfval )
# Used for text snippets, PDF creation or E-Mail templates.
-
module KingPlaceholder
+ extend ActiveSupport::Concern
+ include ActiveSupport::Callbacks
- # sets :placeholders and init Class.placeholders array on inclusion
- def self.included(base)
+ included do
if ActiveSupport::VERSION::MAJOR == 3 && ActiveSupport::VERSION::MINOR > 0
- base.class_attribute :placeholders
+ class_attribute :placeholders
else
- base.send :class_inheritable_accessor, :placeholders
+ class_inheritable_accessor :placeholders
end
- base.placeholders = []
- base.extend(ClassMethods)
+ placeholders = []
end
module ClassMethods
@@ -26,10 +25,11 @@ module ClassMethods
# `before/after_expand_placeholders` hooks are run before the statemachine
# parsing. Define those methods to setup env variables like I18n.locale or
# whatever is required to format output strings.
- # The block gets the current parsed object as method argument
+ # The block is called in scope of the current object(self).
# @example
# def before_expand_placeholders
# I18n.locale = self.language
+ # # self == current object
# end
# def after_expand_placeholders
# I18n.locale = nil
@@ -38,14 +38,13 @@ module ClassMethods
# @param [Array[<Symbol>] fieldnames
def has_placeholders(*fieldnames)
self.placeholders = fieldnames
- include ActiveSupport::Callbacks
define_callbacks :expand_placeholders
set_callback :expand_placeholders, :before, :before_parsing
set_callback :expand_placeholders, :after, :after_parsing
- include InstanceMethods
end
end
+ # TODO inclusion deprecated in ActiveSupport 3.2.7, when gone move methods up into module
module InstanceMethods
# Check if a given field is declared as placeholder
Please sign in to comment.
Something went wrong with that request. Please try again.