light 0.0.1
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 +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +10 -0
- data/Guardfile +24 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/light/model.rb +60 -0
- data/lib/light/version.rb +3 -0
- data/lib/light.rb +6 -0
- data/light.gemspec +23 -0
- data/spec/light/model_spec.rb +61 -0
- data/spec/spec_helper.rb +22 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0902ac2d8ca8ba16869996c1ef04b7ecb2000d97
|
4
|
+
data.tar.gz: d7b5fa19e9126827253e862dcbcabf42b4b9e414
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6ffde4729d408042a7b506d3120585cb97fcdfc664c3badacff70d89814a19fd5e0f112a9fa85528f4cba5318b3fb12e60be56544c14d5d854b1ba0ba9d15e86
|
7
|
+
data.tar.gz: 1f9b9bf84633739b59d1b6cde9f4f02ecd8bb9dc8307d501cc5aea3d2b9c1eb6014b48f21588243913d1209f334f5e36f09b4f019ecf470d8b2194a6693c115b
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard :rspec do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
8
|
+
|
9
|
+
# Rails example
|
10
|
+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
11
|
+
watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
12
|
+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
13
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
14
|
+
watch('config/routes.rb') { "spec/routing" }
|
15
|
+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
16
|
+
|
17
|
+
# Capybara features specs
|
18
|
+
watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
|
19
|
+
|
20
|
+
# Turnip features and steps
|
21
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
22
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
|
23
|
+
end
|
24
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Pawel Niemczyk
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Light
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'light'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install light
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/light/model.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
module Light
|
2
|
+
class Model
|
3
|
+
include ActiveModel::Serialization
|
4
|
+
include ActiveModel::Serializers::JSON
|
5
|
+
extend ActiveModel::Naming
|
6
|
+
extend ActiveModel::Translation
|
7
|
+
include ActiveModel::Validations
|
8
|
+
include ActiveModel::Conversion
|
9
|
+
extend ActiveSupport::Concern
|
10
|
+
|
11
|
+
class << self
|
12
|
+
def attributes(*attrs)
|
13
|
+
attrs.each do |attr|
|
14
|
+
self.send(:attr_accessor, attr)
|
15
|
+
end
|
16
|
+
@__attributes = (@__attributes || []) + attrs
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def equality_state
|
21
|
+
self.class.instance_variable_get(:@__attributes).map do |attr|
|
22
|
+
public_send("#{attr}")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def ==(o)
|
27
|
+
o.class == self.class && o.equality_state == equality_state
|
28
|
+
end
|
29
|
+
|
30
|
+
alias_method :eql?, :==
|
31
|
+
|
32
|
+
def hash
|
33
|
+
equality_state.hash
|
34
|
+
end
|
35
|
+
|
36
|
+
def initialize(params={})
|
37
|
+
params.each do |attr, value|
|
38
|
+
self.public_send("#{attr}=", value)
|
39
|
+
end if params
|
40
|
+
end
|
41
|
+
|
42
|
+
def to_h(opts=nil)
|
43
|
+
self.serializable_hash(opts)
|
44
|
+
end
|
45
|
+
|
46
|
+
def persisted?
|
47
|
+
false
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def attributes
|
53
|
+
{}.tap do |h|
|
54
|
+
(self.class.instance_variable_get(:@__attributes) || []).map do |key|
|
55
|
+
h[key.to_s] = public_send(key.to_sym)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/light.rb
ADDED
data/light.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'light/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "light"
|
8
|
+
spec.version = Light::VERSION
|
9
|
+
spec.authors = ["Pawel Niemczyk"]
|
10
|
+
spec.email = ["pniemczyk@o2.pl"]
|
11
|
+
spec.description = %q{Light models}
|
12
|
+
spec.summary = %q{Light models}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Light::Model do
|
4
|
+
class TestClass < Light::Model
|
5
|
+
attributes :name, :email, :bucket
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:test_data) { {name: 'Pawel', email: 'pniemczyk@o2.pl', bucket: { test_key: 'stuff'}} }
|
9
|
+
before(:each) { @subject = TestClass.new(test_data) }
|
10
|
+
|
11
|
+
describe 'initialize' do
|
12
|
+
|
13
|
+
it 'fillfull instance' do
|
14
|
+
@subject.name.should eq test_data[:name]
|
15
|
+
@subject.email.should eq test_data[:email]
|
16
|
+
@subject.bucket.should eq test_data[:bucket]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#to_h' do
|
21
|
+
it 'default' do
|
22
|
+
@subject.to_h.symbolize_keys.should eq test_data
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'with options' do
|
26
|
+
hash = {'name' => 'Pawel'}
|
27
|
+
@subject.to_h(only: :name).should eq hash
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'equality' do
|
32
|
+
it 'two instance with same data should be eq' do
|
33
|
+
[
|
34
|
+
TestClass.new(test_data) == TestClass.new(test_data),
|
35
|
+
TestClass.new(test_data).eql?(TestClass.new(test_data))
|
36
|
+
].all?.should be_true
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#as_json' do
|
41
|
+
it 'default' do
|
42
|
+
@subject.as_json.should eq test_data.stringify_keys
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'with options' do
|
46
|
+
hash = {'name' => 'Pawel'}
|
47
|
+
@subject.as_json(only: :name).should eq hash.stringify_keys
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#to_json' do
|
52
|
+
it 'default' do
|
53
|
+
@subject.to_json.should eq test_data.to_json
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'with options' do
|
57
|
+
hash = {'name' => 'Pawel'}
|
58
|
+
@subject.to_json(only: :name).should eq hash.to_json
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
|
7
|
+
require 'active_support'
|
8
|
+
require 'active_model'
|
9
|
+
require_relative '../lib/light'
|
10
|
+
|
11
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
14
|
+
config.run_all_when_everything_filtered = true
|
15
|
+
config.filter_run :focus
|
16
|
+
|
17
|
+
# Run specs in random order to surface order dependencies. If you find an
|
18
|
+
# order dependency and want to debug it, you can fix the order by providing
|
19
|
+
# the seed, which is printed after each run.
|
20
|
+
# --seed 1234
|
21
|
+
config.order = 'random'
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: light
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pawel Niemczyk
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Light models
|
42
|
+
email:
|
43
|
+
- pniemczyk@o2.pl
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- .rspec
|
50
|
+
- Gemfile
|
51
|
+
- Guardfile
|
52
|
+
- LICENSE.txt
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- lib/light.rb
|
56
|
+
- lib/light/model.rb
|
57
|
+
- lib/light/version.rb
|
58
|
+
- light.gemspec
|
59
|
+
- spec/light/model_spec.rb
|
60
|
+
- spec/spec_helper.rb
|
61
|
+
homepage: ''
|
62
|
+
licenses:
|
63
|
+
- MIT
|
64
|
+
metadata: {}
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 2.0.3
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: Light models
|
85
|
+
test_files:
|
86
|
+
- spec/light/model_spec.rb
|
87
|
+
- spec/spec_helper.rb
|