active_recordish 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b3b09e23dbc0dbc8acb2caea6da9d2a50cb1f278
4
+ data.tar.gz: 43aaaf02ef33a2ae4ede499144075d135e1b8df1
5
+ SHA512:
6
+ metadata.gz: acb44210d1d873f40ec5ebb3b05b4eba15cf324cbf579254496f30cc68cf540eb8fa4aa5cd6cb453d3ed40eb03aee7bac6236fdb102f5e3a638c9b6013368339
7
+ data.tar.gz: f061c6d69760dd520330664b52ee5659e4d2d5aae45e482f2731f0248534ba2a485fc8559bf8ce95bb4f5d34691921f673b989e680852272383af7abe30998c3
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in active_recordish.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Taiyo Akashi
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,47 @@
1
+ # ActiveRecordish
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ gem 'active_recordish'
8
+
9
+ And then execute:
10
+
11
+ $ bundle
12
+
13
+ Or install it yourself as:
14
+
15
+ $ gem install active_recordish
16
+
17
+ ## Usage
18
+ ```ruby
19
+ require 'active_recordish'
20
+ class Tmp < ActiveRecordish::Base
21
+ def initialize
22
+ @name = "me"
23
+ end
24
+
25
+ def name= _name
26
+ @name = _name
27
+ end
28
+ end
29
+
30
+ tmp = Tmp.new
31
+ tmp.save
32
+ Tmp.all #=> [tmp]
33
+
34
+ tmp2 = Tmp.new
35
+ tmp2.name= "you"
36
+ tmp2.save #=> name is "you"
37
+ Tmp.all #=> [tmp, tmp2]
38
+ Tmp.all.count #=> 2
39
+ ```
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it ( https://github.com/[my-github-username]/active_recordish/fork )
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'active_recordish/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "active_recordish"
8
+ spec.version = ActiveRecordish::VERSION
9
+ spec.authors = ["Taiyo Akashi"]
10
+ spec.email = ["onibakidd@gmail.com"]
11
+ spec.summary = %q{ActiveRecordish is something like ActiveRecord. Assumed usage is using models don't have db relation but have array of instances.}
12
+ spec.description = %q{ActiveRecordish is something like ActiveRecord. Assumed usage is using models don't have db relation but have array of instances.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ end
@@ -0,0 +1,72 @@
1
+ require "active_recordish/version"
2
+
3
+ module ActiveRecordish
4
+ class Base
5
+ class << self
6
+ def all
7
+ @@active_recordish_instances ||= []
8
+ end
9
+ end
10
+
11
+ public
12
+ def save
13
+ @@active_recordish_instances ||= []
14
+ if @@active_recordish_instances.none?{|ari| ari.object_id == self.object_id}
15
+ @@active_recordish_instances << self
16
+ true
17
+ else
18
+ false
19
+ end
20
+ end
21
+
22
+ def destroy
23
+ @@active_recordish_instances.destroy(self)
24
+ end
25
+
26
+ # #where(name: "aaa", old: 13)
27
+ def self.where(options={})
28
+ array = []
29
+ self.all.each do |instance|
30
+ ans = options.all? do |_array|
31
+ at_key = ("@" + _array.first.to_s).to_sym
32
+ if instance.instance_variables.include?(at_key)
33
+ at_value = instance.instance_variable_get(at_key.to_s)
34
+ at_value.to_s == _array.last.to_s
35
+ else
36
+ false
37
+ end
38
+ end
39
+
40
+ array << instance if ans
41
+ end
42
+ array
43
+ end
44
+ end
45
+ # @@active_recordish_instances = []
46
+
47
+ # def self.all
48
+ # @@active_recordish_instances
49
+ # end
50
+
51
+ # def save
52
+ # @active_recordish_id ||= @@active_recordish_instances.count
53
+ # if @@active_recordish_instances.none?{|ari| ari.active_recordish_id == @active_recordish_id}
54
+ # @@active_recordish_instances << self
55
+ # end
56
+ # end
57
+
58
+ # def self.included(klazz)
59
+ # klazz.extend Recordish
60
+ # # klazz.extend XXX
61
+ # end
62
+
63
+ # module Recordish
64
+ # def all
65
+ # @active_recordish_instances
66
+ # end
67
+ # end
68
+
69
+ # module XXX
70
+ # end
71
+ # Your code goes here...
72
+ end
@@ -0,0 +1,3 @@
1
+ module ActiveRecordish
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+ require 'active_recordish'
3
+
4
+ class TestClass < ActiveRecordish::Base
5
+ def initialize
6
+ @output = "aaa"
7
+ end
8
+ end
9
+
10
+ describe ActiveRecordish do
11
+ describe ".all" do
12
+ context "when data is nothing" do
13
+ end
14
+ context "when inclulde 2 data" do
15
+ before do
16
+ TestClass.new.save
17
+ TestClass.new.save
18
+ end
19
+ it "count is 2" do
20
+ expect(TestClass.all.count).to eq 2
21
+ end
22
+ end
23
+ end
24
+
25
+ describe "#save" do
26
+ end
27
+ end
28
+
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+
3
+ # カスタムマッチャを書きたかったらここに。
4
+ RSpec::Matchers.define :my_matcher do |expected|
5
+ match do |actual|
6
+ true
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_recordish
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Taiyo Akashi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-30 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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
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
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: ActiveRecordish is something like ActiveRecord. Assumed usage is using
56
+ models don't have db relation but have array of instances.
57
+ email:
58
+ - onibakidd@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - active_recordish.gemspec
69
+ - lib/active_recordish.rb
70
+ - lib/active_recordish/version.rb
71
+ - spec/active_recordish_spec.rb
72
+ - spec/spec_helper.rb
73
+ homepage: ''
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.2.2
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: ActiveRecordish is something like ActiveRecord. Assumed usage is using models
97
+ don't have db relation but have array of instances.
98
+ test_files:
99
+ - spec/active_recordish_spec.rb
100
+ - spec/spec_helper.rb