[
  {
    "path": ".gitignore",
    "content": "/.bundle/\n/.yardoc\n/Gemfile.lock\n/_yardoc/\n/coverage/\n/doc/\n/pkg/\n/spec/reports/\n/tmp/\n*.bundle\n*.so\n*.o\n*.a\n*.gem\nmkmf.log\n"
  },
  {
    "path": ".rspec",
    "content": "--color\n--require spec_helper\n--warnings\n"
  },
  {
    "path": ".travis.yml",
    "content": "language: ruby\ninstall:\n- bundle install --without interactive\nrvm:\n  - \"2.4.10\"\n  - \"2.5.8\"\n  - \"2.6.6\"\n  - \"2.7.1\"\n  - \"jruby-9.1.17.0\"\n  - \"jruby-9.2.11.1\"\n"
  },
  {
    "path": "CHANGELOG.md",
    "content": "# Change Log\n\nAll notable changes to this project will be documented in this file.\n\n## 3.2.0\n\n- Support `Float` type with `:float`.\n- Tested with Ruby 2.4.\n\n## 3.1.0\n\n- Allow strings 'true' and 'false' to be assigned to boolean attributes and be\n  cast as expected.\n\n## 3.0.0\n\n- **Breaking change**: All casting errors raise `ArgumentError`. Previously some\n  errors during casting would raise `RuntimeError`.\n  Thanks to [@gotascii](https://github.com/gotascii) for the report.\n\n## 2.1.0\n\n- **New feature**: default values.  Allows you to specify a default value like\n  so:\n```\nclass User\n  attribute :name, :string, default: 'Michelle'\nend\n\nUser.new.name\n# => 'Michelle'\n```\n\n## 2.0.0\n\n- **Breaking change**: Rename to `ModelAttribute` (no trailing 's') to avoid name\n  clash with another gem.\n\n## 1.4.0\n\n- **New method**: #changes_for_json  Returns a hash from attribute name to its\n  new value, suitable for serialization to a JSON string.  Easily generate the\n  payload to send in an HTTP PUT to a web service.\n\n- **New attribute type: json**  Store an array/hash/etc. built using the basic\n  JSON data types: nil, numeric, string, boolean, hash and array.\n\n## 1.3.0\n\n- **Breaking change**: Parsing an integer to a time attribute, the integer is\n  treated as the number of milliseconds since the epoch (not the number of\n  seconds).  `attributes_as_json` emits integers for time attributes.\n\n## 1.2.0\n\n- **Breaking change**: `attributes_as_json` removed; replaced with\n  `attributes_for_json`.  You will have to serialize this yourself:\n  `Oj.dump(attributes_for_json, mode: :strict)`.  This allows you to modify the\n  returned hash before serializing it.\n\n## 1.1.0\n\n- Initial release\n"
  },
  {
    "path": "Gemfile",
    "content": "source 'https://rubygems.org'\n\n# Specify your gem's dependencies in model_attribute.gemspec\ngemspec\n\ngroup 'interactive' do\n  gem 'rspec-nc'\n  gem 'guard'\n  gem 'guard-rspec'\nend\n"
  },
  {
    "path": "Guardfile",
    "content": "# A sample Guardfile\n# More info at https://github.com/guard/guard#readme\n\n## Uncomment and set this to only include directories you want to watch\n# directories %w(app lib config test spec feature)\n\n## Uncomment to clear the screen before every task\n# clearing :on\n\n## Make Guard exit when config is changed so it can be restarted\n#\n## Note: if you want Guard to automatically start up again, run guard in a\n## shell loop, e.g.:\n#\n#  $ while bundle exec guard; do echo \"Restarting Guard...\"; done\n#\n## Note: if you are using the `directories` clause above and you are not\n## watching the project directory ('.'), the you will want to move the Guardfile\n## to a watched dir and symlink it back, e.g.\n#\n#  $ mkdir config\n#  $ mv Guardfile config/\n#  $ ln -s config/Guardfile .\n#\n# and, you'll have to watch \"config/Guardfile\" instead of \"Guardfile\"\n#\nwatch (\"Guardfile\") do\n  UI.info \"Exiting because Guard must be restarted for changes to take effect\"\n  exit 0\nend\n\nguard :rspec, cmd: \"bundle exec rspec --format=Nc --format=documentation\", all_on_start: true do\n  require \"guard/rspec/dsl\"\n  dsl = Guard::RSpec::Dsl.new(self)\n\n  # RSpec files\n  rspec = dsl.rspec\n  watch(rspec.spec_helper) { rspec.spec_dir }\n  watch(rspec.spec_support) { rspec.spec_dir }\n  watch(rspec.spec_files)\n\n  # Ruby files\n  ruby = dsl.ruby\n  dsl.watch_spec_files_for(ruby.lib_files)\n\n  watch(%r{lib/*}) { 'spec' }\nend\n"
  },
  {
    "path": "LICENSE.txt",
    "content": "ModelAttribute\n\nCopyright (c) 2015 Microsoft Corporation\n\nAll rights reserved.\n\nMIT License\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n\"Software\"), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\nLIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\nOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\nWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "# ModelAttribute [![Gem Version](https://badge.fury.io/rb/model_attribute.svg)](http://badge.fury.io/rb/model_attribute) [![Build Status](https://travis-ci.org/yammer/model_attribute.svg?branch=master)](https://travis-ci.org/yammer/model_attribute)\n\nSimple attributes for a non-ActiveRecord model.\n\n - Stores attributes in instance variables.\n - Type casting and checking.\n - Dirty tracking.\n - List attribute names and values.\n - Default values for attributes\n - Handles integers, floats, booleans, strings and times - a set of types that are very\n   easy to persist to and parse from JSON.\n - Supports efficient serialization of attributes to JSON.\n - Mass assignment - handy for initializers.\n\nWhy not [Virtus][virtus-gem]?  Virtus doesn't provide dirty tracking, and\ndoesn't integrate with [ActiveModel::Dirty][am-dirty].  So if you're not using\nActiveRecord, but you need attributes with dirty tracking, ModelAttribute may be\nwhat you're after.  For example, it works very well for a model that fronts an\nHTTP web service, and you want dirty tracking so you can PATCH appropriately.\n\nAlso in favor of ModelAttribute:\n\n - It's simple - less than [200 lines of code][source].\n - It supports efficient serialization and deserialization to/from JSON.\n\n[virtus-gem]:https://github.com/solnic/virtus\n[am-dirty]:https://github.com/rails/rails/blob/master/activemodel/lib/active_model/dirty.rb\n[source]:https://github.com/yammer/model_attribute/blob/master/lib/model_attribute.rb\n\n## Integrating with Rails\n\nIf you're using ModelAttribute in a Rails application, you will probably want to\naugment your model with other methods to make it behave more like\n`ActiveRecord`.  `ActiveModel` provides a very useful set of mixins,\ndescribed in the [Rails guide][active-model-guide].  You can also see an example\nof the methods we found useful at Yammer described in [this blog\npost][yammer-blog-post], with full source in [this Gist][active-record-mimic].\n\n[active-model-guide]:https://guides.rubyonrails.org/active_model_basics.html\n[yammer-blog-post]:https://medium.com/yammer-engineering/activerecord-stole-my-data-and-now-i-want-it-back-3041ac4eb163\n[active-record-mimic]:https://gist.github.com/dwaller/5474304cfea354a9701d\n\n## Usage\n\n```ruby\nrequire 'model_attribute'\nclass User\n  extend ModelAttribute\n  attribute :id,         :integer\n  attribute :paid,       :boolean\n  attribute :name,       :string\n  attribute :created_at, :time\n  attribute :grades,     :json\n\n  def initialize(attributes = {})\n    set_attributes(attributes)\n  end\nend\n\nUser.attributes # => [:id, :paid, :name, :created_at, :grades]\nuser = User.new\n\nuser.attributes # => {:id=>nil, :paid=>nil, :name=>nil, :created_at=>nil, :grades=>nil}\n\n# An integer attribute\nuser.id # => nil\n\nuser.id = 3\nuser.id # => 3\n\n# Stores values that convert cleanly to an integer\nuser.id = '5'\nuser.id # => 5\n\n# Protects you against nonsense assignment\nuser.id = '5error'\nArgumentError: invalid value for Integer(): \"5error\"\n\n# A boolean attribute\nuser.paid # => nil\nuser.paid = true\n\n# Booleans also define a predicate method (ending in '?')\nuser.paid?  # => true\n\n# Conversion from strings used by databases.\nuser.paid = 'f'\nuser.paid # => false\nuser.paid = 't'\nuser.paid # => true\nuser.paid = 'false'\nuser.paid # => false\nuser.paid = 'true'\nuser.paid # => true\n\n# A :time attribute\nuser.created_at = Time.now\nuser.created_at # => 2015-01-08 15:57:05 +0000\n\n# Also converts from other reasonable time formats\nuser.created_at = \"2014-12-25 14:00:00 +0100\"\nuser.created_at # => 2014-12-25 13:00:00 +0000\nuser.created_at = Date.parse('2014-01-08')\nuser.created_at # => 2014-01-08 00:00:00 +0000\nuser.created_at = DateTime.parse(\"2014-12-25 13:00:45\")\nuser.created_at # => 2014-12-25 13:00:45 +0000\n# Convert from seconds since the epoch\nuser.created_at = Time.now.to_f\nuser.created_at # => 2015-01-08 16:23:02 +0000\n# Or milliseconds since the epoch\nuser.created_at = 1420734182000\nuser.created_at # => 2015-01-08 16:23:02 +0000\n\n# A :json attribute is schemaless and accepts the basic JSON types - hash,\n# array, nil, numeric, string and boolean.\nuser.grades = {'maths' => 'A', 'history' => 'C'}\nuser.grades # => {\"maths\"=>\"A\", \"history\"=>\"C\"}\nuser.grades = ['A', 'A*', 'C']\nuser.grades # => [\"A\", \"A*\", \"C\"]\nuser.grades = 'AAB'\nuser.grades # => \"AAB\"\nuser.grades = Time.now\n# => ArgumentError: JSON only supports nil, numeric, string, boolean and arrays and hashes of those.\n\n# read_attribute and write_attribute methods\nuser.read_attribute(:created_at)\nuser.write_attribute(:name, 'Fred')\n\n# View attributes\nuser.attributes # => {:id=>5, :paid=>true, :name=>\"Fred\", :created_at=>2015-01-08 15:57:05 +0000, :grades=>{\"maths\"=>\"A\", \"history\"=>\"C\"}}\nuser.inspect # => \"#<User id: 5, paid: true, name: \\\"Fred\\\", created_at: 2015-01-08 15:57:05 +0000, grades: {\\\"maths\\\"=>\\\"A\\\", \\\"history\\\"=>\\\"C\\\"}>\"\n\n# Mass assignment\nuser.set_attributes(name: \"Sally\", paid: false)\nuser.attributes # => {:id=>5, :paid=>false, :name=>\"Sally\", :created_at=>2015-01-08 15:57:05 +0000}\n\n# Efficient JSON serialization and deserialization.\n# Attributes with nil values are omitted.\nuser.attributes_for_json\n# => {\"id\"=>5, \"paid\"=>true, \"name\"=>\"Fred\", \"created_at\"=>1421171317762}\nrequire 'oj'\nOj.dump(user.attributes_for_json, mode: :strict)\n# => \"{\\\"id\\\":5,\\\"paid\\\":true,\\\"name\\\":\\\"Fred\\\",\\\"created_at\\\":1421171317762}\"\nuser2 = User.new(Oj.load(json, strict: true))\n\n# Change tracking.  A much smaller set of functions than that provided by\n# ActiveModel::Dirty.\nuser.changes # => {:id=>[nil, 5], :paid=>[nil, true], :created_at=>[nil, 2015-01-08 15:57:05 +0000], :name=>[nil, \"Fred\"]}\nuser.name_changed?  # => true\n# If you need the new values to send as a PUT to a web service\nuser.changes_for_json # => {\"id\"=>5, \"paid\"=>true, \"name\"=>\"Fred\", \"created_at\"=>1421171317762}\n# If you're imitating ActiveRecord behaviour, changes are cleared after\n# after_save callbacks, but before after_commit callbacks.\nuser.changes.clear\nuser.changes # => {}\n\n# Equality if all the attribute values match\nanother = User.new\nanother.id = 5\nanother.paid = true\nanother.created_at = user.created_at\nanother.name = 'Fred'\n\nuser == another   # => true\nuser === another  # => true\nuser.eql? another # => true\n\n# Making some attributes private\n\nclass User\n  extend ModelAttribute\n  attribute :events, :string\n  private :events=\n\n  def initialize(attributes)\n    # Pass flag to set_attributes to allow setting attributes with private writers\n    set_attributes(attributes, true)\n  end\n\n  def add_event(new_event)\n    events ||= \"\"\n    events += new_event\n  end\nend\n\n# Supporting default attributes\n\nclass UserWithDefaults\n  extend ModelAttribute\n\n  attribute :name, :string, default: 'Charlie'\nend\n\nUserWithDefaults.attribute_defaults # => {:name=>\"Charlie\"}\n\nuser = UserWithDefaults.new\nuser.name # => \"Charlie\"\nuser.read_attribute(:name) # => \"Charlie\"\nuser.attributes # => {:name=>\"Charlie\"}\n# attributes_for_json omits defaults to keep the JSON compact\nuser.attributes_for_json # => {}\n# You can add them back in if you need them\nuser.attributes_for_json.merge(user.class.attribute_defaults) # => {:name=>\"Charlie\"}\n# A default isn't a change\nuser.changes # => {}\nuser.changes_for_json # => {}\n\nuser.name = 'Bob'\nuser.attributes # => {:name=>\"Bob\"}\n```\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'model_attribute'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install model_attribute\n\n## Testing\n\nRunning specs:\n\n    $ rspec\n\n## Contributing\n\n1. [Fork it](https://github.com/yammer/model_attribute/fork)\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## Code of Conduct\n\nThis project has adopted the [Microsoft Open Source Code of\nConduct](https://opensource.microsoft.com/codeofconduct/). For more information\nsee the [Code of Conduct\nFAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact\n[opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional\nquestions or comments.\n"
  },
  {
    "path": "Rakefile",
    "content": "require 'bundler/gem_tasks'\nrequire 'rspec/core/rake_task'\nRSpec::Core::RakeTask.new(:spec) do |t|\n  t.pattern = Dir.glob('spec/**/*_spec.rb')\n  t.rspec_opts = '--format documentation'\nend\n\ntask :default => :spec\n"
  },
  {
    "path": "lib/model_attribute/casts.rb",
    "content": "module ModelAttribute\n  module Casts\n    class << self\n      def cast(value, type)\n        return nil if value.nil?\n\n        case type\n        when :integer\n          int = Integer(value)\n          float = Float(value)\n          raise ArgumentError, \"Can't cast #{value.inspect} to an integer without loss of precision\" unless int == float\n          int\n        when :float\n          Float(value)\n        when :boolean\n          if !!value == value\n            value\n          elsif value == 't' || value == 'true'\n            true\n          elsif value == 'f' || value == 'false'\n            false\n          else\n            raise ArgumentError, \"Can't cast #{value.inspect} to boolean\"\n          end\n        when :time\n          case value\n          when Time\n            value\n          when Date, DateTime\n            value.to_time\n          when Integer\n            # Assume milliseconds since epoch.\n            Time.at(value / 1000.0)\n          when Numeric\n            # Numeric, but not an integer. Assume seconds since epoch.\n            Time.at(value)\n          else\n            Time.parse(value)\n          end\n        when :string\n          String(value)\n        when :json\n          if valid_json?(value)\n            value\n          else\n            raise ArgumentError, \"JSON only supports nil, numeric, string, boolean and arrays and hashes of those.\"\n          end\n        else\n          raise UnsupportedTypeError.new(type)\n        end\n      end\n\n      private\n\n      def valid_json?(value)\n        (value == nil         ||\n         value == true        ||\n         value == false       ||\n         value.is_a?(Numeric) ||\n         value.is_a?(String)  ||\n         (value.is_a?(Array) && valid_json_array?(value)) ||\n         (value.is_a?(Hash)  && valid_json_hash?(value) ))\n      end\n\n      def valid_json_array?(array)\n        array.all? { |value| valid_json?(value) }\n      end\n\n      def valid_json_hash?(hash)\n        hash.all? do |key, value|\n          key.is_a?(String) && valid_json?(value)\n        end\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/model_attribute/errors.rb",
    "content": "module ModelAttribute\n  class InvalidAttributeNameError < StandardError\n    def initialize(attribute_name)\n      super \"Invalid attribute name #{attribute_name.inspect}\"\n    end\n  end\n\n  class UnsupportedTypeError < StandardError\n    def initialize(type)\n      types_list = ModelAttribute::SUPPORTED_TYPES.map(&:inspect).join(', ')\n      super \"Unsupported type #{type.inspect}. Must be one of #{types_list}.\"\n    end\n  end\nend\n"
  },
  {
    "path": "lib/model_attribute/version.rb",
    "content": "module ModelAttribute\n  VERSION = \"3.2.0\"\nend\n"
  },
  {
    "path": "lib/model_attribute.rb",
    "content": "require \"model_attribute/version\"\nrequire \"model_attribute/casts\"\nrequire \"model_attribute/errors\"\nrequire \"time\"\n\nmodule ModelAttribute\n  SUPPORTED_TYPES = [:integer, :float, :boolean, :string, :time, :json]\n\n  def self.extended(base)\n    base.send(:include, InstanceMethods)\n    base.instance_variable_set('@attribute_names',    [])\n    base.instance_variable_set('@attribute_types',    {})\n    base.instance_variable_set('@attribute_defaults', {})\n  end\n\n  def attribute(name, type, opts = {})\n    name = name.to_sym\n    type = type.to_sym\n    raise UnsupportedTypeError.new(type) unless SUPPORTED_TYPES.include?(type)\n\n    @attribute_names          << name\n    @attribute_types[name]    = type\n    @attribute_defaults[name] = opts[:default] if opts.key?(:default)\n\n    self.class_eval(<<-CODE, __FILE__, __LINE__ + 1)\n      def #{name}=(value)\n        write_attribute(#{name.inspect}, value, #{type.inspect})\n      end\n\n      def #{name}\n        read_attribute(#{name.inspect})\n      end\n\n      def #{name}_changed?\n        !!changes[#{name.inspect}]\n      end\n    CODE\n\n    if type == :boolean\n      self.class_eval(<<-CODE, __FILE__, __LINE__ + 1)\n        def #{name}?\n          !!read_attribute(#{name.inspect})\n        end\n      CODE\n    end\n  end\n\n  def attributes\n    @attribute_names\n  end\n\n  def attribute_defaults\n    @attribute_defaults\n  end\n\n  module InstanceMethods\n    def write_attribute(name, value, type = nil)\n      name = name.to_sym\n\n      # Don't want to expose attribute types as a method on the class, so access\n      # via a back door.\n      type ||= self.class.instance_variable_get('@attribute_types')[name]\n      raise InvalidAttributeNameError.new(name) unless type\n\n      value = Casts.cast(value, type)\n      return if value == read_attribute(name)\n\n      if changes.has_key? name\n        original = changes[name].first\n      else\n        original = read_attribute(name)\n      end\n\n      if original == value\n        changes.delete(name)\n      else\n        changes[name] = [original, value]\n      end\n\n      instance_variable_set(\"@#{name}\", value)\n    end\n\n    def read_attribute(name)\n      ivar_name = \"@#{name}\"\n      if instance_variable_defined?(ivar_name)\n        instance_variable_get(ivar_name)\n      elsif !self.class.attributes.include?(name.to_sym)\n        raise InvalidAttributeNameError.new(name)\n      else\n        self.class.attribute_defaults[name.to_sym]\n      end\n    end\n\n    def attributes\n      self.class.attributes.each_with_object({}) do |name, attributes|\n        attributes[name] = read_attribute(name)\n      end\n    end\n\n    def set_attributes(attributes, can_set_private_attrs = false)\n      attributes.each do |key, value|\n        send(\"#{key}=\", value) if respond_to?(\"#{key}=\", can_set_private_attrs)\n      end\n    end\n\n    def ==(other)\n      return true if equal?(other)\n      if respond_to?(:id)\n        other.kind_of?(self.class) && id == other.id\n      else\n        other.kind_of?(self.class) && attributes == other.attributes\n      end\n    end\n    alias_method :eql?, :==\n\n    def changes\n      @changes ||= {}\n    end\n\n    # Attributes suitable for serializing to a JSON string.\n    #\n    #  - Attribute keys are strings (for 'strict' JSON dumping).\n    #  - Attributes with a default or nil value are omitted to speed serialization.\n    #  - :time attributes are serialized as an Integer giving the number of\n    #    milliseconds since the epoch.\n    def attributes_for_json\n      self.class.attributes.each_with_object({}) do |name, attributes|\n        value = read_attribute(name)\n        if value != self.class.attribute_defaults[name.to_sym]\n          value = (value.to_f * 1000).to_i if value.is_a? Time\n          attributes[name.to_s] = value\n        end\n      end\n    end\n\n    # Changed attributes suitable for serializing to a JSON string.  Returns a\n    # hash from attribute name (as a string) to the new value of that attribute,\n    # for attributes that have changed.\n    #\n    #  - :time attributes are serialized as an Integer giving the number of\n    #    milliseconds since the epoch.\n    #  - Unlike attributes_for_json, attributes that have changed to a nil value\n    #    *are* included.\n    def changes_for_json\n      hash = {}\n      changes.each do |attr_name, (_old_value, new_value)|\n        new_value = (new_value.to_f * 1000).to_i if new_value.is_a? Time\n        hash[attr_name.to_s] = new_value\n      end\n\n      hash\n    end\n\n    # Includes the class name and all the attributes and their values.  e.g.\n    # \"#<User id: 1, paid: true, name: \\\"Fred\\\", created_at: 2014-12-25 08:00:00 +0000>\"\n    def inspect\n      attribute_string = self.class.attributes.map do |key|\n        \"#{key}: #{read_attribute(key).inspect}\"\n      end.join(', ')\n      \"#<#{self.class} #{attribute_string}>\"\n    end\n  end\nend\n"
  },
  {
    "path": "model_attribute.gemspec",
    "content": "# coding: utf-8\nlib = File.expand_path('../lib', __FILE__)\n$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)\nrequire 'model_attribute/version'\n\nGem::Specification.new do |spec|\n  spec.name          = \"model_attribute\"\n  spec.version       = ModelAttribute::VERSION\n  spec.authors       = [\"David Waller\"]\n  spec.email         = [\"dwaller@yammer-inc.com\"]\n  spec.summary       = %q{Attributes for non-ActiveRecord models}\n  spec.description   = <<-EOF\n    Attributes for non-ActiveRecord models.\n    Smaller and simpler than Virtus, and adds dirty tracking.\n  EOF\n  spec.homepage      = \"https://github.com/yammer/model_attribute\"\n  spec.license       = \"MIT\"\n\n  spec.files         = `git ls-files -z`.split(\"\\x0\")\n  spec.executables   = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }\n  spec.test_files    = spec.files.grep(%r{^(test|spec|features)/})\n  spec.require_paths = [\"lib\"]\n\n  spec.add_development_dependency \"bundler\"\n  spec.add_development_dependency \"rake\",    \">= 12.3.3\"\n  spec.add_development_dependency \"rspec\",   \"~> 3.1\"\nend\n"
  },
  {
    "path": "performance_comparison.rb",
    "content": "require 'benchmark'\n$LOAD_PATH << \"lib\"\n\nBenchmark.bm(41) do |bm|\n  bm.report(\"Virtus load\") do\n    require 'virtus'\n\n    class VirtusUser\n      include Virtus.model\n      attribute :id,         Integer\n      attribute :name,       String\n      attribute :paid,       Boolean\n      attribute :updated_at, DateTime\n    end\n  end\n\n  bm.report(\"ModelAttribute load\") do\n    require_relative 'lib/model_attribute'\n\n    class ModelAttributeUser\n      extend ModelAttribute\n      attribute :id,         :integer\n      attribute :name,       :string\n      attribute :paid,       :boolean\n      attribute :updated_at, :time\n    end\n  end\nend\n\nBenchmark.bm(41) do |bm|\n  vu  = VirtusUser.new\n  mau = ModelAttributeUser.new\n  bm.report(\"Virtus         assign integer\")             { 10_000.times {  vu.id = rand(100_000) } }\n  bm.report(\"ModelAttribute assign integer\")             { 10_000.times { mau.id = rand(100_000) } }\n  bm.report(\"Virtus         assign integer from string\") { 10_000.times {  vu.id = rand(100_000).to_s } }\n  bm.report(\"ModelAttribute assign integer from string\") { 10_000.times { mau.id = rand(100_000).to_s } }\n  bm.report(\"Virtus         assign time\")                { 10_000.times {  vu.updated_at = Time.now } }\n  bm.report(\"ModelAttribute assign time\")                { 10_000.times { mau.updated_at = Time.now } }\n  bm.report(\"Virtus         assign DateTime\")            { 10_000.times {  vu.updated_at = DateTime.now } }\n  bm.report(\"ModelAttribute assign DateTime\")            { 10_000.times { mau.updated_at = DateTime.now } }\n  bm.report(\"Virtus         assign time from epoch\")     { 10_000.times {  vu.updated_at = Time.now.to_f } }\n  bm.report(\"ModelAttribute assign time from epoch\")     { 10_000.times { mau.updated_at = Time.now.to_f } }\n  bm.report(\"Virtus         assign time from string\")    { 10_000.times {  vu.updated_at = \"2014-12-25 06:00:00\" } }\n  bm.report(\"ModelAttribute assign time from string\")    { 10_000.times { mau.updated_at = \"2014-12-25 06:00:00\" } }\nend\n\n__END__\n$ ruby -v\nruby 1.9.3p545 (2014-02-24 revision 45159) [x86_64-darwin13.3.0]\n$ ruby performance_comparison.rb\n                                                user     system      total        real\nVirtus load                                0.120000   0.040000   0.160000 (  0.207931)\nModelAttribute load                        0.020000   0.010000   0.030000 (  0.027237)\n                                                user     system      total        real\nVirtus         assign integer              0.010000   0.000000   0.010000 (  0.013906)\nModelAttribute assign integer              0.030000   0.000000   0.030000 (  0.033674)\nVirtus         assign integer from string  0.170000   0.000000   0.170000 (  0.171892)\nModelAttribute assign integer from string  0.050000   0.000000   0.050000 (  0.042726)\nVirtus         assign time                 0.080000   0.000000   0.080000 (  0.089792)\nModelAttribute assign time                 0.060000   0.000000   0.060000 (  0.057887)\nVirtus         assign DateTime             0.030000   0.000000   0.030000 (  0.026447)\nModelAttribute assign DateTime             0.200000   0.000000   0.200000 (  0.204524)\nVirtus         assign time from epoch      0.230000   0.010000   0.240000 (  0.225557)\nModelAttribute assign time from epoch      0.110000   0.000000   0.110000 (  0.113315)\nVirtus         assign time from string     0.260000   0.000000   0.260000 (  0.264467)\nModelAttribute assign time from string     0.450000   0.000000   0.450000 (  0.444686)\n"
  },
  {
    "path": "spec/model_attributes_spec.rb",
    "content": "class User\n  extend ModelAttribute\n  attribute :id,            :integer\n  attribute :paid,          :boolean\n  attribute :name,          :string\n  attribute :created_at,    :time\n  attribute :profile,       :json\n  attribute :reward_points, :integer, default: 0\n  attribute :win_rate,      :float\n\n  def initialize(attributes = {})\n    set_attributes(attributes)\n  end\nend\n\nclass UserWithoutId\n  extend ModelAttribute\n  attribute :paid,       :boolean\n  attribute :name,       :string\n  attribute :created_at, :time\n\n  def initialize(attributes = {})\n    set_attributes(attributes)\n  end\nend\n\nRSpec.describe \"a class using ModelAttribute\" do\n  describe \"class methods\" do\n    describe \".attribute\" do\n      context \"passed an unrecognised type\" do\n        it \"raises an error\" do\n          expect do\n            User.attribute :address, :custom_type\n          end.to raise_error(ModelAttribute::UnsupportedTypeError,\n                             \"Unsupported type :custom_type. \" +\n                             \"Must be one of :integer, :float, :boolean, :string, :time, :json.\")\n        end\n      end\n    end\n\n    describe \".attributes\" do\n      it \"returns an array of attribute names as symbols\" do\n        expect(User.attributes).to eq([:id, :paid, :name, :created_at, :profile, :reward_points, :win_rate])\n      end\n    end\n\n    describe \".attribute_defaults\" do\n      it \"returns a hash of attributes that have non-nil defaults\" do\n        expect(User.attribute_defaults).to eq({reward_points: 0})\n      end\n    end\n  end\n\n  describe \"an instance of the class\" do\n    let(:user) { User.new }\n\n    describe \"an integer attribute (id)\" do\n      it \"is nil when unset\" do\n        expect(user.id).to be_nil\n      end\n\n      it \"stores an integer\" do\n        user.id = 3\n        expect(user.id).to eq(3)\n      end\n\n      it \"stores an integer passed as a float\" do\n        user.id = 3.0\n        expect(user.id).to eq(3)\n      end\n\n      it \"raises when passed a float with non-zero decimal part\" do\n        expect { user.id = 3.3 }.to raise_error(ArgumentError)\n      end\n\n      it \"parses an integer string\" do\n        user.id = '3'\n        expect(user.id).to eq(3)\n      end\n\n      it \"raises if passed a string it can't parse\" do\n        expect { user.id = '3a' }.to raise_error(ArgumentError,\n                                                 /invalid value for Integer.*: \"3a\"/)\n      end\n\n      it \"stores nil\" do\n        user.id = 3\n        user.id = nil\n        expect(user.id).to be_nil\n      end\n\n      it \"does not provide an id? method\" do\n        expect(user).to_not respond_to(:id?)\n        expect { user.id? }.to raise_error(NoMethodError)\n      end\n    end\n\n    describe \"a float attribute (win_rate)\" do\n      it \"stores a float\" do\n        user.win_rate = 35.62\n        expect(user.win_rate).to eq(35.62)\n      end\n\n      it \"parses a float string\" do\n        user.win_rate = 35.62\n        expect(user.win_rate).to eq(35.62)\n      end\n    end\n\n    describe \"a boolean attribute (paid)\" do\n      it \"is nil when unset\" do\n        expect(user.paid).to be_nil\n      end\n\n      it \"stores true\" do\n        user.paid = true\n        expect(user.paid).to eq(true)\n      end\n\n      it \"stores false\" do\n        user.paid = false\n        expect(user.paid).to eq(false)\n      end\n\n      it \"parses 't' as true\" do\n        user.paid = 't'\n        expect(user.paid).to eq(true)\n      end\n\n      it \"parses 'f' as false\" do\n        user.paid = 'f'\n        expect(user.paid).to eq(false)\n      end\n\n      it \"parses 'false' to false\" do\n        user.paid = 'false'\n        expect(user.paid).to eq(false)\n      end\n\n      it \"parses 'true' to true\" do\n        user.paid = 'true'\n        expect(user.paid).to eq(true)\n      end\n\n      it \"raises if passed a string it can't parse\" do\n        expect { user.paid = '3a' }.to raise_error(ArgumentError,\n                                                   'Can\\'t cast \"3a\" to boolean')\n      end\n\n      it \"stores nil\" do\n        user.paid = true\n        user.paid = nil\n        expect(user.paid).to be_nil\n      end\n\n      describe \"#paid?\" do\n        it \"returns false when unset\" do\n          expect(user.paid?).to eq(false)\n        end\n\n        it \"returns false for false attributes\" do\n          user.paid = false\n          expect(user.paid?).to eq(false)\n        end\n\n        it \"returns true for true attributes\" do\n          user.paid = true\n          expect(user.paid?).to eq(true)\n        end\n      end\n    end\n\n    describe \"a string attribute (name)\" do\n      it \"is nil when unset\" do\n        expect(user.name).to be_nil\n      end\n\n      it \"stores a string\" do\n        user.name = 'Fred'\n        expect(user.name).to eq('Fred')\n      end\n\n      it \"casts an integer to a string\" do\n        user.name = 3\n        expect(user.name).to eq('3')\n      end\n\n      it \"stores nil\" do\n        user.name = 'Fred'\n        user.name = nil\n        expect(user.name).to be_nil\n      end\n\n      it \"does not provide a name? method\" do\n        expect(user).to_not respond_to(:name?)\n        expect { user.name? }.to raise_error(NoMethodError)\n      end\n    end\n\n    describe \"a time attribute (created_at)\" do\n      let(:now_time) { Time.now }\n\n      it \"is nil when unset\" do\n        expect(user.created_at).to be_nil\n      end\n\n      it \"stores a Time object\" do\n        user.created_at = now_time\n        expect(user.created_at).to eq(now_time)\n      end\n\n      it \"parses floats as seconds past the epoch\" do\n        user.created_at = now_time.to_f\n        # Going via float loses precision, so use be_within\n        expect(user.created_at).to be_within(0.0001).of(now_time)\n        expect(user.created_at).to be_a_kind_of(Time)\n      end\n\n      it \"parses integers as milliseconds past the epoch\" do\n        user.created_at = (now_time.to_f * 1000).to_i\n        # Truncating to milliseconds loses precision, so use be_within\n        expect(user.created_at).to be_within(0.001).of(now_time)\n        expect(user.created_at).to be_a_kind_of(Time)\n      end\n\n      it \"parses strings to date/times\" do\n        user.created_at = \"2014-12-25 14:00:00 +0100\"\n        expect(user.created_at).to eq(Time.new(2014, 12, 25, 13, 00, 00, 0))\n      end\n\n      it \"raises for unparseable strings\" do\n        expect { user.created_at = \"Today, innit?\" }.to raise_error(ArgumentError,\n                                                        'no time information in \"Today, innit?\"')\n      end\n\n      it \"converts Dates to Time\" do\n        user.created_at = Date.parse(\"2014-12-25\")\n        expect(user.created_at).to eq(Time.new(2014, 12, 25, 00, 00, 00))\n      end\n\n      it \"converts DateTime to Time\" do\n        user.created_at = DateTime.parse(\"2014-12-25 13:00:45 +0000\")\n        expect(user.created_at.utc).to eq(Time.new(2014, 12, 25, 13, 00, 45, 0))\n      end\n\n      it \"stores nil\" do\n        user.created_at = now_time\n        user.created_at = nil\n        expect(user.created_at).to be_nil\n      end\n\n      it \"does not provide a created_at? method\" do\n        expect(user).to_not respond_to(:created_at?)\n        expect { user.created_at? }.to raise_error(NoMethodError)\n      end\n    end\n\n    describe \"a json attribute (profile)\" do\n      it \"is nil when unset\" do\n        expect(user.profile).to be_nil\n      end\n\n      it \"stores a string\" do\n        user.profile = 'Incomplete'\n        expect(user.profile).to eq('Incomplete')\n      end\n\n      it \"stores an integer\" do\n        user.profile = 3\n        expect(user.profile).to eq(3)\n      end\n\n      it \"stores true\" do\n        user.profile = true\n        expect(user.profile).to eq(true)\n      end\n\n      it \"stores false\" do\n        user.profile = false\n        expect(user.profile).to eq(false)\n      end\n\n      it \"stores an array\" do\n        user.profile = [1, 2, 3]\n        expect(user.profile).to eq([1, 2, 3])\n      end\n\n      it \"stores a hash\" do\n        user.profile = {'skill' => 8}\n        expect(user.profile).to eq({'skill' => 8})\n      end\n\n      it \"stores nested hashes and arrays\" do\n        json = {'array' => [1,\n                            2,\n                            true,\n                            {'inner' => true},\n                            ['inside', {}]\n                           ],\n                'hash'  => {'getting' => {'nested' => 'yes'}},\n                'boolean' => true\n               }\n        user.profile = json\n        expect(user.profile).to eq(json)\n      end\n\n      it \"raises when passed an object not supported by JSON\" do\n        expect { user.profile = Object.new }.to raise_error(ArgumentError,\n          \"JSON only supports nil, numeric, string, boolean and arrays and hashes of those.\")\n      end\n\n      it \"raises when passed a hash with a non-string key\" do\n        expect { user.profile = {1 => 'first'} }.to raise_error(ArgumentError,\n          \"JSON only supports nil, numeric, string, boolean and arrays and hashes of those.\")\n      end\n\n      it \"raises when passed a hash with an unsupported value\" do\n        expect { user.profile = {'first' => :symbol} }.to raise_error(ArgumentError,\n          \"JSON only supports nil, numeric, string, boolean and arrays and hashes of those.\")\n      end\n\n      it \"raises when passed an array with an unsupported value\" do\n        expect { user.profile = [1, 2, nil, :symbol] }.to raise_error(ArgumentError,\n          \"JSON only supports nil, numeric, string, boolean and arrays and hashes of those.\")\n      end\n\n      it \"stores nil\" do\n        user.profile = {'foo' => 'bar'}\n        user.profile = nil\n        expect(user.profile).to be_nil\n      end\n\n      it \"does not provide a profile? method\" do\n        expect(user).to_not respond_to(:profile?)\n        expect { user.profile? }.to raise_error(NoMethodError)\n      end\n    end\n\n    describe 'a defaulted attribute (reward_points)' do\n      it \"returns the default when unset\" do\n        expect(user.reward_points).to eq(0)\n      end\n    end\n\n    describe \"#write_attribute\" do\n      it \"does the same casting as using the writer method\" do\n        user.write_attribute(:id, '3')\n        expect(user.id).to eq(3)\n      end\n\n      it \"raises an error if passed an invalid attribute name\" do\n        expect do\n          user.write_attribute(:spelling_mistake, '3')\n        end.to raise_error(ModelAttribute::InvalidAttributeNameError,\n                           \"Invalid attribute name :spelling_mistake\")\n      end\n    end\n\n    describe \"#read_attribute\" do\n      it \"returns the value of an attribute that has been set\" do\n        user.write_attribute(:id, 3)\n        expect(user.read_attribute(:id)).to eq(user.id)\n      end\n\n      it \"returns nil for an attribute that has not been set\" do\n        expect(user.read_attribute(:id)).to be_nil\n      end\n\n      context \"for an attribute with a default\" do\n        it \"returns the default if the attribute has not been set\" do\n          expect(user.read_attribute(:reward_points)).to eq(0)\n        end\n      end\n\n      it \"raises an error if passed an invalid attribute name\" do\n        expect do\n          user.read_attribute(:spelling_mistake)\n        end.to raise_error(ModelAttribute::InvalidAttributeNameError,\n                           \"Invalid attribute name :spelling_mistake\")\n      end\n    end\n\n    describe \"#changes\" do\n      let(:changes) { user.changes }\n\n      context \"for a model instance created with no attributes except defaults\" do\n        it \"is empty\" do\n          expect(changes).to be_empty\n        end\n      end\n\n      context \"when an attribute is set via a writer method\" do\n        before(:each) { user.id = 3 }\n\n        it \"has an entry from attribute name to [old, new] pair\" do\n          expect(changes).to include(:id => [nil, 3])\n        end\n\n        context \"when an attribute is set again\" do\n          before(:each) { user.id = 5 }\n\n          it \"shows the latest value for the attribute\" do\n            expect(changes).to include(:id => [nil, 5])\n          end\n        end\n\n        context \"when an attribute is set back to its original value\" do\n          before(:each) { user.id = nil }\n\n          it \"does not have an entry for the attribute\" do\n            expect(changes).to_not include(:id)\n          end\n        end\n      end\n    end\n\n    describe \"#changes_for_json\" do\n      let(:changes_for_json) { user.changes_for_json }\n\n      context \"for a model instance created with no attributes\" do\n        it \"is empty\" do\n          expect(changes_for_json).to be_empty\n        end\n      end\n\n      context \"when an attribute is set via a writer method\" do\n        before(:each) { user.id = 3 }\n\n        it \"has an entry from attribute name (as a string) to the new value\" do\n          expect(changes_for_json).to include('id' => 3)\n        end\n\n        context \"when an attribute is set again\" do\n          before(:each) { user.id = 5 }\n\n          it \"shows the latest value for the attribute\" do\n            expect(changes_for_json).to include('id' => 5)\n          end\n        end\n\n        context \"when an attribute is set back to its original value\" do\n          before(:each) { user.id = nil }\n\n          it \"does not have an entry for the attribute\" do\n            expect(changes_for_json).to_not include('id')\n          end\n        end\n\n        context \"if the returned hash is modified\" do\n          before(:each) { user.changes_for_json.clear }\n\n          it \"does not affect subsequent results from changes_for_json\" do\n            expect(changes_for_json).to include('id' => 3)\n          end\n        end\n      end\n\n      it \"serializes time attributes as JSON integer\" do\n        user.created_at = Time.now\n        expect(changes_for_json).to include(\"created_at\" => kind_of(Integer))\n      end\n    end\n\n    describe \"#id_changed?\" do\n      context \"with no changes\" do\n        it \"returns false\" do\n          expect(user.id_changed?).to eq(false)\n        end\n      end\n\n      context \"with changes\" do\n        before(:each) { user.id = 3 }\n\n        it \"returns true\" do\n          expect(user.id_changed?).to eq(true)\n        end\n      end\n    end\n\n    describe \"#attributes\" do\n      let(:time_now) { Time.now }\n\n      before(:each) do\n        user.id = 1\n        user.paid = true\n        user.created_at = time_now\n      end\n\n      it \"returns a hash including each set attribute\" do\n        expect(user.attributes).to include(id: 1, paid: true, created_at: time_now)\n      end\n\n      it \"returns a hash with a nil value for each unset attribute\" do\n        expect(user.attributes).to include(name: nil)\n      end\n    end\n\n    describe \"#attributes_for_json\" do\n      let(:time_now) { Time.now }\n\n      before(:each) do\n        user.id = 1\n        user.paid = true\n        user.created_at = time_now\n      end\n\n      it \"serializes integer attributes as JSON integer\" do\n        expect(user.attributes_for_json).to include(\"id\" => 1)\n      end\n\n      it \"serializes time attributes as JSON integer\" do\n        expect(user.attributes_for_json).to include(\"created_at\" => kind_of(Integer))\n      end\n\n      it \"serializes string attributes as JSON string\" do\n        user.name = 'Fred'\n        expect(user.attributes_for_json).to include(\"name\" => \"Fred\")\n      end\n\n      it \"leaves JSON attributes unchanged\" do\n        json = {'interests' => ['coding', 'social networks'], 'rank' => 15}\n        user.profile = json\n        expect(user.attributes_for_json).to include(\"profile\" => json)\n      end\n\n      it \"omits attributes still set to the default value\" do\n        expect(user.attributes_for_json).to_not include(\"name\", \"reward_points\")\n      end\n\n      it \"includes an attribute changed from its default value\" do\n        user.name = \"Fred\"\n        expect(user.attributes_for_json).to include(\"name\" => \"Fred\")\n      end\n\n      it \"includes an attribute changed from its default value to nil\" do\n        user.reward_points = nil\n        expect(user.attributes_for_json).to include(\"reward_points\" => nil)\n      end\n    end\n\n    describe \"#set_attributes\" do\n      it \"allows mass assignment of attributes\" do\n        user.set_attributes(id: 5, name: \"Sally\")\n        expect(user.attributes).to include(id: 5, name: \"Sally\")\n      end\n\n      it \"ignores keys that have no writer method\" do\n        user.set_attributes(id: 5, species: \"Human\")\n        expect(user.attributes).to_not include(species: \"Human\")\n      end\n\n      context \"for an attribute with a private writer method\" do\n        before(:all) { User.send(:private, :name=) }\n        after(:all)  { User.send(:public,  :name=) }\n\n        it \"does not set the attribute\" do\n          user.set_attributes(id: 5, name: \"Sally\")\n          expect(user.attributes).to_not include(name: \"Sally\")\n        end\n\n        it \"sets the attribute if the flag is passed\" do\n          user.set_attributes({id: 5, name: \"Sally\"}, true)\n          expect(user.attributes).to include(name: \"Sally\")\n        end\n      end\n    end\n\n    describe \"#inspect\" do\n      let(:user) do\n        User.new(id: 1,\n                 name: \"Fred\",\n                 created_at: \"2014-12-25 08:00 +0000\",\n                 paid: true,\n                 profile: {'interests' => ['coding', 'social networks'], 'rank' => 15},\n                 win_rate: 35.62)\n      end\n\n      it \"includes integer attributes as 'name: value'\" do\n        expect(user.inspect).to include(\"id: 1\")\n      end\n\n      it \"includes boolean attributes as 'name: true/false'\" do\n        expect(user.inspect).to include(\"paid: true\")\n      end\n\n      it \"includes string attributes as 'name: \\\"string\\\"'\" do\n        expect(user.inspect).to include('name: \"Fred\"')\n      end\n\n      it \"includes time attributes as 'name: <ISO 8601>'\" do\n        expect(user.inspect).to include(\"created_at: 2014-12-25 08:00:00 +0000\")\n      end\n\n      it \"includes json attributes as 'name: inspected_json'\" do\n        expect(user.inspect).to include('profile: {\"interests\"=>[\"coding\", \"social networks\"], \"rank\"=>15}')\n      end\n\n      it \"includes defaulted attributes\" do\n        expect(user.inspect).to include('reward_points: 0')\n      end\n\n      it \"includes the class name\" do\n        expect(user.inspect).to include(\"User\")\n      end\n\n      it \"looks like '#<User id: 1, paid: true, name: ..., created_at: ...>'\" do\n        expect(user.inspect).to eq(\"#<User id: 1, paid: true, name: \\\"Fred\\\", created_at: 2014-12-25 08:00:00 +0000, profile: {\\\"interests\\\"=>[\\\"coding\\\", \\\"social networks\\\"], \\\"rank\\\"=>15}, reward_points: 0, win_rate: 35.62>\")\n      end\n    end\n\n    describe 'equality with :id field' do\n      let(:u1) { User.new(id: 1, name: 'David') }\n\n      context '#==' do\n        it 'returns true when ids match, regardless of other attributes' do\n          u2 = User.new(id: 1, name: 'Dave')\n          expect(u1).to eq(u2)\n        end\n\n        it 'returns false when ids do not match' do\n          u2 = User.new(id: 2, name: 'David')\n          expect(u1).to_not eq(u2)\n        end\n      end\n\n      context '#eql?' do\n        it 'returns true when ids match, regardless of other attributes' do\n          u2 = User.new(id: 1, name: 'Dave')\n          expect(u1).to eql(u2)\n        end\n\n        it 'returns false when ids do not match' do\n          u2 = User.new(id: 2, name: 'David')\n          expect(u1).to_not eql(u2)\n        end\n      end\n    end\n\n    describe 'equality without :id field' do\n      let(:u1) { UserWithoutId.new(name: 'David') }\n\n      context \"for models with different attribute values\" do\n        let(:u2) { UserWithoutId.new(name: 'Dave') }\n\n        it \"#== returns false\" do\n          expect(u1).to_not eq(u2)\n        end\n\n        it \"#eql? returns false\" do\n          expect(u1).to_not eql(u2)\n        end\n      end\n\n      context \"for models with different attributes set\" do\n        let(:u2) { UserWithoutId.new }\n\n        it \"#== returns false\" do\n          expect(u1).to_not eq(u2)\n        end\n\n        it \"#eql? returns false\" do\n          expect(u1).to_not eql(u2)\n        end\n      end\n\n      context \"for models with the same attributes set to the same values\" do\n        let(:u2) { UserWithoutId.new(name: 'David') }\n\n        it \"#== returns true\" do\n          expect(u1).to eq(u2)\n        end\n\n        it \"#eql? returns true\" do\n          expect(u1).to eql(u2)\n        end\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "spec/spec_helper.rb",
    "content": "require 'model_attribute'\n\n# This file was generated by the `rspec --init` command. Conventionally, all\n# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.\n# The generated `.rspec` file contains `--require spec_helper` which will cause this\n# file to always be loaded, without a need to explicitly require it in any files.\n#\n# Given that it is always loaded, you are encouraged to keep this file as\n# light-weight as possible. Requiring heavyweight dependencies from this file\n# will add to the boot time of your test suite on EVERY test run, even for an\n# individual file that may not need all of that loaded. Instead, consider making\n# a separate helper file that requires the additional dependencies and performs\n# the additional setup, and require it from the spec files that actually need it.\n#\n# The `.rspec` file also contains a few flags that are not defaults but that\n# users commonly want.\n#\n# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration\nRSpec.configure do |config|\n  # rspec-expectations config goes here. You can use an alternate\n  # assertion/expectation library such as wrong or the stdlib/minitest\n  # assertions if you prefer.\n  config.expect_with :rspec do |expectations|\n    # This option will default to `true` in RSpec 4. It makes the `description`\n    # and `failure_message` of custom matchers include text for helper methods\n    # defined using `chain`, e.g.:\n    # be_bigger_than(2).and_smaller_than(4).description\n    #   # => \"be bigger than 2 and smaller than 4\"\n    # ...rather than:\n    #   # => \"be bigger than 2\"\n    expectations.include_chain_clauses_in_custom_matcher_descriptions = true\n  end\n\n  # rspec-mocks config goes here. You can use an alternate test double\n  # library (such as bogus or mocha) by changing the `mock_with` option here.\n  config.mock_with :rspec do |mocks|\n    # Prevents you from mocking or stubbing a method that does not exist on\n    # a real object. This is generally recommended, and will default to\n    # `true` in RSpec 4.\n    mocks.verify_partial_doubles = true\n  end\n\n  # Limits the available syntax to the non-monkey patched syntax that is recommended.\n  # For more details, see:\n  #   - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax\n  #   - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/\n  #   - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching\n  config.disable_monkey_patching!\n\n  # This setting enables warnings. It's recommended, but in some cases may\n  # be too noisy due to issues in dependencies.\n  config.warnings = true\n\n# The settings below are suggested to provide a good initial experience\n# with RSpec, but feel free to customize to your heart's content.\n=begin\n  # These two settings work together to allow you to limit a spec run\n  # to individual examples or groups you care about by tagging them with\n  # `:focus` metadata. When nothing is tagged with `:focus`, all examples\n  # get run.\n  config.filter_run :focus\n  config.run_all_when_everything_filtered = true\n\n  # Many RSpec users commonly either run the entire suite or an individual\n  # file, and it's useful to allow more verbose output when running an\n  # individual spec file.\n  if config.files_to_run.one?\n    # Use the documentation formatter for detailed output,\n    # unless a formatter has already been configured\n    # (e.g. via a command-line flag).\n    config.default_formatter = 'doc'\n  end\n\n  # Print the 10 slowest examples and example groups at the\n  # end of the spec run, to help surface which specs are running\n  # particularly slow.\n  config.profile_examples = 10\n\n  # Run specs in random order to surface order dependencies. If you find an\n  # order dependency and want to debug it, you can fix the order by providing\n  # the seed, which is printed after each run.\n  #     --seed 1234\n  config.order = :random\n\n  # Seed global randomization in this process using the `--seed` CLI option.\n  # Setting this allows you to use `--seed` to deterministically reproduce\n  # test failures related to randomization by passing the same `--seed` value\n  # as the one that triggered the failure.\n  Kernel.srand config.seed\n=end\nend\n"
  }
]