opium 1.0.0.beta → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7949dfc491925078b8d64f4b093524530d183608
4
- data.tar.gz: d9949725cb81e568d62bd46c1be3fb28af0c2b08
3
+ metadata.gz: ab3129797b81cdb23362431fddf4ee5d6deaf1d9
4
+ data.tar.gz: a6f8105866f4101f9f4eb2f0661696777846741b
5
5
  SHA512:
6
- metadata.gz: 012d1e38fab68ab65636e981b5c06861dd6acdee6e4d0d025ee9ac72b6a9c7216e3fd15e4a9b999adff35fcb706253520f78d5fda386430240ad31511d67b6a3
7
- data.tar.gz: 496fd7162e76f218f08caaa37cb300bb3662843577c4c77f4cb31ab98e00f8f34606cab80540ba482c9bda15fc0069c429284f584c5f98bd7db0cb36e50ed462
6
+ metadata.gz: 0047e98730f67c24d819a704c9a22f1f89e8f686bf2c7be9dbc4c1a7eadbeae8f63e897a315dfff72e3c58bfd0db07f08a5977b395f43b1a79f5498cf9de7808
7
+ data.tar.gz: 7f34b3d49b52392291584f1b9c1e33b9be7b6273d4a2aca50234bb05a1f70ebe44113e7944629ab145f93a08d03923caa245134f543022e9cb9d25861656f6a1
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  Provides an intuitive, Mongoid-inspired mapping layer between your application's object space and Parse.
4
4
 
5
+ [![Gem Version](https://badge.fury.io/rb/opium.svg)](http://badge.fury.io/rb/opium)
5
6
  [![Build Status](https://travis-ci.org/joshuabowers/opium.svg?branch=master)](https://travis-ci.org/joshuabowers/opium)
6
7
  [![Coverage Status](https://img.shields.io/coveralls/joshuabowers/opium.svg)](https://coveralls.io/r/joshuabowers/opium)
7
8
  [![Code Climate](https://codeclimate.com/github/joshuabowers/opium/badges/gpa.svg)](https://codeclimate.com/github/joshuabowers/opium)
@@ -0,0 +1,16 @@
1
+ require 'rails/generators'
2
+ require 'generators/opium/model_generator'
3
+
4
+ module Opium
5
+ module Generators
6
+ class UserGenerator < ::Rails::Generators::Base
7
+ desc "Creates an Opium user model"
8
+
9
+ argument :attributes, type: :array, default: [], banner: "field:type field:type"
10
+
11
+ def run_model_generator
12
+ generate 'model', *['user', *attributes, '--parent=opium/user']
13
+ end
14
+ end
15
+ end
16
+ end
@@ -85,6 +85,8 @@ module Opium
85
85
  !@requires_heightened_privileges.nil?
86
86
  end
87
87
 
88
+ alias_method :has_heightened_privileges?, :requires_heightened_privileges?
89
+
88
90
  private
89
91
 
90
92
  def http( method, options, &block )
@@ -0,0 +1,27 @@
1
+ module Opium
2
+ module Model
3
+ module Inheritable
4
+ extend ActiveSupport::Concern
5
+
6
+ module ClassMethods
7
+ def inherited( subclass )
8
+ self.resource_name
9
+
10
+ [
11
+ :@ruby_canonical_field_names,
12
+ :@parse_canonical_field_names,
13
+ :@object_prefix,
14
+ :@added_headers,
15
+ :@requires_heightened_privileges,
16
+ :@fields,
17
+ :@resource_name
18
+ ].each do |iv|
19
+ origin = self.instance_variable_get( iv )
20
+ can_copy = ![TrueClass, FalseClass, NilClass].include?( origin.class )
21
+ subclass.instance_variable_set( iv, can_copy ? origin.dup : origin )
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
data/lib/opium/model.rb CHANGED
@@ -14,6 +14,7 @@ require 'opium/model/queryable'
14
14
  require 'opium/model/criteria'
15
15
  require 'opium/model/scopable'
16
16
  require 'opium/model/findable'
17
+ require 'opium/model/inheritable'
17
18
  require 'opium/model/kaminari'
18
19
 
19
20
  module Opium
@@ -33,6 +34,7 @@ module Opium
33
34
  include Callbacks
34
35
  include Scopable
35
36
  include Findable
37
+ include Inheritable
36
38
  end
37
39
 
38
40
  def initialize( attributes = {} )
data/lib/opium/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Opium
2
- VERSION = "1.0.0.beta"
2
+ VERSION = "1.0.0"
3
3
  end
data/opium.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Joshua Bowers"]
10
10
  spec.email = ["joshua.bowers+code@gmail.com"]
11
11
  spec.summary = %q{An Object Parse.com Mapping technology for defining models.}
12
- spec.description = %q{Provides an intuitive, Mongoid-inspired mapping layer between your application's object space and Parse.'}
12
+ spec.description = %q{Provides an intuitive, Mongoid-inspired mapping layer between your application's object space and Parse.}
13
13
  spec.homepage = "https://github.com/joshuabowers/opium"
14
14
  spec.license = "MIT"
15
15
 
@@ -31,8 +31,8 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency "pry-nav"
32
32
  spec.add_development_dependency "coveralls"
33
33
 
34
- spec.add_development_dependency "rails"
35
- spec.add_development_dependency "kaminari"
34
+ # spec.add_development_dependency "rails"
35
+ # spec.add_development_dependency "kaminari"
36
36
 
37
37
  spec.add_dependency "activemodel", "~> 4.0"
38
38
  spec.add_dependency "faraday", "~> 0.9"
@@ -20,7 +20,7 @@ describe Opium::Model::Connectable do
20
20
  it { is_expected.to respond_to( :as_resource, :resource_name ).with(1).argument }
21
21
  it { is_expected.to respond_to( :http_get, :http_post, :http_delete ).with(1).argument }
22
22
  it { is_expected.to respond_to( :http_put ).with(2).arguments }
23
- it { is_expected.to respond_to( :requires_heightened_privileges!, :requires_heightened_privileges? ) }
23
+ it { is_expected.to respond_to( :requires_heightened_privileges!, :requires_heightened_privileges?, :has_heightened_privileges? ) }
24
24
 
25
25
  describe '.object_prefix' do
26
26
  it { expect( subject.object_prefix ).to eq 'classes' }
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+
3
+ describe Opium::Model::Inheritable do
4
+ before do
5
+ stub_const( 'Model', Class.new do
6
+ include Opium::Model::Inheritable
7
+ end )
8
+ end
9
+
10
+ subject { Model }
11
+
12
+ it { expect( subject ).to respond_to( :inherited ).with(1).argument }
13
+
14
+ context 'within a subclass' do
15
+ before do
16
+ stub_const( 'Game', Class.new do
17
+ include Opium::Model
18
+ field :title, type: String
19
+ field :price, type: Float
20
+
21
+ no_object_prefix!
22
+ requires_heightened_privileges!
23
+ end )
24
+ stub_const( 'MobileGame', Class.new( Game ) do
25
+ field :device, type: String
26
+ end )
27
+ end
28
+
29
+ subject { MobileGame }
30
+
31
+ it { is_expected.to be <= Game }
32
+
33
+ it { expect( subject.object_prefix ).to eq subject.superclass.object_prefix }
34
+ it { expect( subject.ruby_canonical_field_names ).to include( subject.superclass.ruby_canonical_field_names ) }
35
+ it { expect( subject.parse_canonical_field_names ).to include( subject.superclass.parse_canonical_field_names ) }
36
+ it { expect( subject.added_headers ).to include( subject.superclass.added_headers ) }
37
+ it { expect( subject.resource_name ).to eq subject.superclass.resource_name }
38
+ it { is_expected.to have_heightened_privileges }
39
+
40
+ it { expect( subject ).to respond_to( :field, :fields ) }
41
+
42
+ it "inherits its parent's fields" do
43
+ expect( subject.fields.keys ).to include( 'title', 'price' )
44
+ end
45
+
46
+ it 'has its own defined fields' do
47
+ expect( subject.fields.keys ).to include( 'device' )
48
+ end
49
+
50
+ it "does not alter its parent's fields" do
51
+ expect( Game.fields.keys ).to_not include( 'device' )
52
+ end
53
+
54
+ it 'has accessors and mutators for its fields' do
55
+ expect( subject.new ).to respond_to( :title, :title=, :price, :price=, :device, :device= )
56
+ end
57
+
58
+ it 'has its own canonical_field_names' do
59
+ expect( subject.ruby_canonical_field_names.keys ).to include( 'device' )
60
+ expect( subject.parse_canonical_field_names.keys ).to include( 'device' )
61
+ end
62
+
63
+ it "does not alter its parent's canonical_field_names" do
64
+ expect( Game.ruby_canonical_field_names.keys ).to_not include( 'device' )
65
+ expect( Game.parse_canonical_field_names.keys ).to_not include( 'device' )
66
+ end
67
+ end
68
+ end
@@ -12,38 +12,29 @@ describe Opium::Model do
12
12
 
13
13
  subject { Event }
14
14
 
15
- it { should respond_to( :model_name, :validates, :define_model_callbacks ) }
16
- it { should respond_to( :field ).with(2).arguments }
17
- it { should respond_to( :delete_all, :find ).with(1).argument }
18
- it { should respond_to( :connection ) }
19
- it { should respond_to( :human_attribute_name, :lookup_ancestors ) }
20
-
21
- describe 'instance' do
22
- subject { Event.new }
23
-
24
- it { should respond_to( :attributes ) }
25
- it { should respond_to( :serializable_hash, :as_json, :from_json ) }
26
- it { should respond_to( :changes, :changed? ) }
27
- it { should respond_to( :inspect ) }
28
- it { should respond_to( :to_key, :to_model ) }
15
+ it { is_expected.to be <= Opium::Model::Connectable }
16
+ it { is_expected.to be <= Opium::Model::Persistable }
17
+ it { is_expected.to be <= Opium::Model::Dirty }
18
+ it { is_expected.to be <= Opium::Model::Fieldable }
19
+ it { is_expected.to be <= Opium::Model::Serialization }
20
+ it { is_expected.to be <= Opium::Model::Attributable }
21
+ it { is_expected.to be <= Opium::Model::Queryable }
22
+ it { is_expected.to be <= Opium::Model::Callbacks }
23
+ it { is_expected.to be <= Opium::Model::Scopable }
24
+ it { is_expected.to be <= Opium::Model::Findable }
25
+ it { is_expected.to be <= Opium::Model::Inheritable }
29
26
 
30
- its(:attributes) do
31
- should_not be_nil
32
- should be_a_kind_of( Hash )
33
- end
34
- end
35
-
36
- describe 'inspect' do
37
- describe 'within a blank model' do
27
+ describe '#inspect' do
28
+ context 'within a blank model' do
38
29
  subject { Event.new }
39
30
 
40
- it { subject.inspect.should == '#<Event id: nil, created_at: nil, updated_at: nil, name: nil, occurred_at: nil, severe: nil>' }
31
+ it { expect( subject.inspect ).to eq '#<Event id: nil, created_at: nil, updated_at: nil, name: nil, occurred_at: nil, severe: nil>' }
41
32
  end
42
33
 
43
- describe 'within a model with data' do
34
+ context 'within a model with data' do
44
35
  let(:event_time) { Time.now }
45
36
  subject { Event.new id: 'abc123', name: 'ping', occurred_at: event_time, severe: false }
46
- it { subject.inspect.should == "#<Event id: \"abc123\", created_at: nil, updated_at: nil, name: \"ping\", occurred_at: #{event_time.to_datetime.inspect}, severe: false>" }
37
+ it { expect( subject.inspect ).to eq "#<Event id: \"abc123\", created_at: nil, updated_at: nil, name: \"ping\", occurred_at: #{event_time.to_datetime.inspect}, severe: false>" }
47
38
  end
48
39
  end
49
40
  end
@@ -192,4 +192,22 @@ describe Opium::User do
192
192
 
193
193
  it_behaves_like 'a varying privileges user', :save, [:put, :update]
194
194
  it_behaves_like 'a varying privileges user', :delete, [:delete, :delete]
195
+
196
+ context 'within a subclass' do
197
+ before do
198
+ stub_const( 'SpecialUser', Class.new(Opium::User) do
199
+ field :has_web_access, type: Boolean
200
+ end )
201
+ end
202
+
203
+ subject { SpecialUser }
204
+
205
+ it { is_expected.to be <= Opium::User }
206
+ it { is_expected.to respond_to( :field, :fields ) }
207
+ it { expect( subject.fields.keys ).to include( 'username', 'password', 'email', 'has_web_access' ) }
208
+
209
+ it { expect( subject ).to have_heightened_privileges }
210
+ it { expect( subject.object_prefix ).to be_empty }
211
+ it { expect( subject.resource_name ).to eq 'users' }
212
+ end
195
213
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opium
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Bowers
@@ -178,34 +178,6 @@ dependencies:
178
178
  - - ">="
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
- - !ruby/object:Gem::Dependency
182
- name: rails
183
- requirement: !ruby/object:Gem::Requirement
184
- requirements:
185
- - - ">="
186
- - !ruby/object:Gem::Version
187
- version: '0'
188
- type: :development
189
- prerelease: false
190
- version_requirements: !ruby/object:Gem::Requirement
191
- requirements:
192
- - - ">="
193
- - !ruby/object:Gem::Version
194
- version: '0'
195
- - !ruby/object:Gem::Dependency
196
- name: kaminari
197
- requirement: !ruby/object:Gem::Requirement
198
- requirements:
199
- - - ">="
200
- - !ruby/object:Gem::Version
201
- version: '0'
202
- type: :development
203
- prerelease: false
204
- version_requirements: !ruby/object:Gem::Requirement
205
- requirements:
206
- - - ">="
207
- - !ruby/object:Gem::Version
208
- version: '0'
209
181
  - !ruby/object:Gem::Dependency
210
182
  name: activemodel
211
183
  requirement: !ruby/object:Gem::Requirement
@@ -249,7 +221,7 @@ dependencies:
249
221
  - !ruby/object:Gem::Version
250
222
  version: '0.9'
251
223
  description: Provides an intuitive, Mongoid-inspired mapping layer between your application's
252
- object space and Parse.'
224
+ object space and Parse.
253
225
  email:
254
226
  - joshua.bowers+code@gmail.com
255
227
  executables: []
@@ -268,6 +240,7 @@ files:
268
240
  - lib/generators/opium/model_generator.rb
269
241
  - lib/generators/opium/templates/config.yml
270
242
  - lib/generators/opium/templates/model.rb
243
+ - lib/generators/opium/user_generator.rb
271
244
  - lib/opium.rb
272
245
  - lib/opium/config.rb
273
246
  - lib/opium/extensions.rb
@@ -296,6 +269,7 @@ files:
296
269
  - lib/opium/model/field.rb
297
270
  - lib/opium/model/fieldable.rb
298
271
  - lib/opium/model/findable.rb
272
+ - lib/opium/model/inheritable.rb
299
273
  - lib/opium/model/kaminari.rb
300
274
  - lib/opium/model/kaminari/queryable.rb
301
275
  - lib/opium/model/kaminari/scopable.rb
@@ -329,6 +303,7 @@ files:
329
303
  - spec/opium/model/dirty_spec.rb
330
304
  - spec/opium/model/fieldable_spec.rb
331
305
  - spec/opium/model/findable_spec.rb
306
+ - spec/opium/model/inheritable_spec.rb
332
307
  - spec/opium/model/kaminari/queryable_spec.rb
333
308
  - spec/opium/model/kaminari/scopable_spec.rb
334
309
  - spec/opium/model/kaminari_spec.rb
@@ -355,9 +330,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
355
330
  version: '0'
356
331
  required_rubygems_version: !ruby/object:Gem::Requirement
357
332
  requirements:
358
- - - ">"
333
+ - - ">="
359
334
  - !ruby/object:Gem::Version
360
- version: 1.3.1
335
+ version: '0'
361
336
  requirements: []
362
337
  rubyforge_project:
363
338
  rubygems_version: 2.4.6
@@ -387,6 +362,7 @@ test_files:
387
362
  - spec/opium/model/dirty_spec.rb
388
363
  - spec/opium/model/fieldable_spec.rb
389
364
  - spec/opium/model/findable_spec.rb
365
+ - spec/opium/model/inheritable_spec.rb
390
366
  - spec/opium/model/kaminari/queryable_spec.rb
391
367
  - spec/opium/model/kaminari/scopable_spec.rb
392
368
  - spec/opium/model/kaminari_spec.rb