Sha256: 242363c8a9b1c33a037864b42dff8b6ed19a6612e671b68b00da2517a2e90951

Contents?: true

Size: 558 Bytes

Versions: 4

Compression:

Stored size: 558 Bytes

Contents

module ActiveMocker

  class Field

    attr_reader :name, :type, :options

    def initialize(name: name, type: type, options: options)
      @name    = name
      @type    = type
      @options = options
      create_option_methods
    end

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

    def create_option_methods
      options.each do |opt|
        key, value = opt.first
        self.instance_variable_set("@#{key}", value)
        define_singleton_method(key) {instance_variable_get("@#{key}")}
      end
    end

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
active_mocker-1.0.0 lib/active_mocker/field.rb
active_mocker-0.4.0 lib/active_mocker/field.rb
active_mocker-0.3.1 lib/active_mocker/field.rb
active_mocker-0.1.1 lib/active_mocker/field.rb