File: coercion.rb

package info (click to toggle)
ruby-hashie 5.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 884 kB
  • sloc: ruby: 7,049; sh: 8; makefile: 6
file content (25 lines) | stat: -rw-r--r-- 739 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
module Hashie
  module Extensions
    module Dash
      module Coercion
        # Extends a Dash with the ability to define coercion for properties.

        def self.included(base)
          base.send :include, Hashie::Extensions::Coercion
          base.extend ClassMethods
        end

        module ClassMethods
          # Defines a property on the Dash. Options are the standard
          # <tt>Hashie::Dash#property</tt> options plus:
          #
          # * <tt>:coerce</tt> - The class into which you want the property coerced.
          def property(property_name, options = {})
            super
            coerce_key property_name, options[:coerce] if options[:coerce]
          end
        end
      end
    end
  end
end