Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 5 files changed
  • 0 comments
  • 1 contributor
4 Gemfile.lock
@@ -89,7 +89,7 @@ GEM
89 89 ruby-progressbar (~> 0.0.10)
90 90 gherkin (2.9.1)
91 91 json (>= 1.4.6)
92   - heroku (2.21.3)
  92 + heroku (2.22.0)
93 93 launchy (>= 0.3.2)
94 94 netrc (~> 0.7.1)
95 95 rest-client (~> 1.6.1)
@@ -155,7 +155,7 @@ GEM
155 155 rspec-core (2.9.0)
156 156 rspec-expectations (2.9.0)
157 157 diff-lcs (~> 1.1.3)
158   - rspec-instafail (0.2.2)
  158 + rspec-instafail (0.2.3)
159 159 rspec-mocks (2.9.0)
160 160 rspec-rails (2.9.0)
161 161 actionpack (>= 3.0)
32 app/models/model.rb
... ... @@ -0,0 +1,32 @@
  1 +# Based on Rails 4's ActiveModel::Model
  2 +module Model
  3 + def self.included(base)
  4 + base.class_eval do
  5 + extend ActiveModel::Naming
  6 + extend ActiveModel::Translation
  7 + include ActiveModel::Conversion
  8 +
  9 + # Create individual accessors and attributes method
  10 + def self.expose_attributes *attr_names
  11 + attr_accessor *attr_names
  12 + define_method :attributes do
  13 + Hash[attr_names.map {|a| [a, send(a)]}]
  14 + end
  15 + end
  16 + end
  17 + end
  18 +
  19 + def initialize(attributes={})
  20 + attributes.each do |attr, value|
  21 + public_send("#{attr}=", value) if respond_to?("#{attr}=")
  22 + end
  23 + end
  24 +
  25 + def persisted?
  26 + false
  27 + end
  28 +
  29 + def ==(other)
  30 + other.class == self.class && other.attributes == attributes
  31 + end
  32 +end
4 app/models/session.rb
... ... @@ -1,7 +1,7 @@
1   -require_relative "../../lib/active_model/model"
  1 +require_relative "model"
2 2
3 3 class Session
4   - include ActiveModel::Model
  4 + include Model
5 5
6 6 expose_attributes :title, :description, :created_at
7 7
4 app/models/user.rb
... ... @@ -1,6 +1,6 @@
1   -require_relative "../../lib/active_model/model"
  1 +require_relative "model"
2 2
3 3 class User
4   - include ActiveModel::Model
  4 + include Model
5 5 expose_attributes :ein, :password
6 6 end
34 lib/active_model/model.rb
... ... @@ -1,34 +0,0 @@
1   -module ActiveModel
2   - # Based on Rails 4's ActiveModel::Model
3   - module Model
4   - def self.included(base)
5   - base.class_eval do
6   - extend ActiveModel::Naming
7   - extend ActiveModel::Translation
8   - include ActiveModel::Conversion
9   -
10   - # Creates individual accessors and attributes method
11   - def self.expose_attributes *attr_names
12   - attr_accessor *attr_names
13   - define_method :attributes do
14   - Hash[attr_names.map {|a| [a, send(a)]}]
15   - end
16   - end
17   - end
18   - end
19   -
20   - def initialize(attributes={})
21   - attributes.each do |attr, value|
22   - public_send("#{attr}=", value) if respond_to?("#{attr}=")
23   - end
24   - end
25   -
26   - def persisted?
27   - false
28   - end
29   -
30   - def ==(other)
31   - other.class == self.class && other.attributes == attributes
32   - end
33   - end
34   -end

No commit comments for this range

Something went wrong with that request. Please try again.