Sha256: ac2aa0945cfa4e13aae3cd10b085db46dd1db60b956bafabfc429725497d3418

Contents?: true

Size: 905 Bytes

Versions: 4

Compression:

Stored size: 905 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.to_sym)
      end
    end

  end #Fields
end#KingFormat

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
king_views-1.1.6 king_format/lib/model_mixins/has_percent_fields.rb
king_views-1.1.5 king_format/lib/model_mixins/has_percent_fields.rb
king_views-1.1.4 king_format/lib/model_mixins/has_percent_fields.rb
king_views-1.1.3 king_format/lib/model_mixins/has_percent_fields.rb