Sha256: e84af76244394fd9d940bdd24178ffc8a5c506c0406efc9021ba240c18923388

Contents?: true

Size: 590 Bytes

Versions: 5

Compression:

Stored size: 590 Bytes

Contents

module ActiveMocker

  class Field

    attr_accessor :name, :type, :options

    def initialize(name, type, options)
      @name    = name
      @type    = type
      @options = {}
      options.each{|hash| @options[hash.keys.first] = hash.values.first}
      create_option_methods
    end

    def to_h
      {name: name, type: type, options: options}
    end

    alias_method :to_hash, :to_h

    def create_option_methods
      options.each do |key, value|
        self.instance_variable_set("@#{key}", value)
        self.class.send(:attr_accessor, key)
      end
    end

  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
active_mocker-1.3.2 lib/active_mocker/field.rb
active_mocker-1.3.1 lib/active_mocker/field.rb
active_mocker-1.3 lib/active_mocker/field.rb
active_mocker-1.2.4 lib/active_mocker/field.rb
active_mocker-1.2.3 lib/active_mocker/field.rb