Sha256: e1625df6ff198d253889aea646dba84ecd292c4b7be7f7f06d93364595213490

Contents?: true

Size: 935 Bytes

Versions: 9

Compression:

Stored size: 935 Bytes

Contents

module KingFormat
  #TODO:
  # split money / percent
  # kick numeric? only used in list helper
  module PercentFields

    def self.included(base)
      base.send :class_inheritable_accessor, :percent_fields
      base.percent_fields = []
      base.extend(ClassMethods)
    end


    module ClassMethods
      #  Defines the fields returned by self.percent_fields.
      # ===== Parameter
      # fieldnames<Array[Symbol]>:: fieldnames/instance method names as symbols
      # ==== Example
      # class Invoice
      #   has_percent_fields :total, :amout, :calculated_tax
      #
      def has_percent_fields(*fieldnames)
        self.percent_fields = fieldnames
        #include InstanceMethods
      end

      # Check if a given field is declared as percent
      def is_percent_field?(fieldname)
        self.percent_fields.include?(fieldname) if self.respond_to?(:percent_fields)
      end
    end

  end #Fields
end#KingFormat

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
king_views-1.1.2 king_format/lib/model_mixins/has_percent_fields.rb
king_views-1.1.1 king_format/lib/model_mixins/has_percent_fields.rb
king_views-1.1.0 king_format/lib/model_mixins/has_percent_fields.rb
king_views-1.0.5 king_format/lib/model_mixins/has_percent_fields.rb
king_views-1.0.4 king_format/lib/model_mixins/has_percent_fields.rb
king_views-1.0.3 king_format/lib/model_mixins/has_percent_fields.rb
king_views-1.0.2 king_format/lib/model_mixins/has_percent_fields.rb
king_views-1.0.1 king_format/lib/model_mixins/has_percent_fields.rb
king_views-1.0.0 king_format/lib/model_mixins/has_percent_fields.rb