my_active_file 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/README.md +35 -0
- data/Rakefile +2 -0
- data/lib/my_active_file.rb +91 -0
- data/lib/my_active_file/version.rb +3 -0
- data/my_active_file.gemspec +17 -0
- metadata +62 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8f66f42138749acae1ce11cfdaeac7394fa4fba764a52864a58861086112ec60
|
4
|
+
data.tar.gz: 00fcb200f3d149b8c622b3f53d08701fb21c9229548dfc9b13ec93fb30a51039
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fc296042801c04fe6c454e95e7524a69cf7feca58f0adc146bd815cee358d3943838c4f86a979272eabce4322af38c12d2bf7fa8b4f498e7bd668f37a6449321
|
7
|
+
data.tar.gz: c0c34c6a1d94a6aa15996c06c6b7f76dfb86a3db99c7494183d548d49895e86b1deb891b5ff5fac2d2cc8a725bc4579ea8d1b2287eb28be3705ddd94164c118c
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# MyActiveFile
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/my_active_file`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'my_active_file'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install my_active_file
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/my_active_file.
|
data/Rakefile
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
require "my_active_file/version"
|
2
|
+
|
3
|
+
module MyActiveFile
|
4
|
+
def save
|
5
|
+
@new_record = false
|
6
|
+
File.open("db/revistas/#{@id}.yml", 'w') do |file|
|
7
|
+
file.puts serialize
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def destroy
|
12
|
+
return unless @destroyed || @new_record
|
13
|
+
@destroyed = true
|
14
|
+
FileUtils.rm "db/revistas/#{@id}.yml"
|
15
|
+
end
|
16
|
+
|
17
|
+
module ClassMethods
|
18
|
+
def field(name, required: false, default: '')
|
19
|
+
@fields ||= []
|
20
|
+
@fields << Field.new(name, required, default)
|
21
|
+
class_eval %$
|
22
|
+
attr_accessor *#{@fields.map(&:name)}
|
23
|
+
attr_reader :id, :destroyed, :new_record
|
24
|
+
def initialize(#{@fields.map(&:to_argument).join(', ')})
|
25
|
+
@id = self.class.next_id
|
26
|
+
@destroyed = false
|
27
|
+
@new_record = true
|
28
|
+
#{@fields.map(&:to_assign).join("\n")}
|
29
|
+
end $
|
30
|
+
end
|
31
|
+
|
32
|
+
def find(id)
|
33
|
+
unless File.exist?("db/revistas/#{id}.yml")
|
34
|
+
raise DocumentNotFound, "Arquivo #{id} não encontrado.", caller
|
35
|
+
end
|
36
|
+
YAML.load File.open("db/revistas/#{id}.yml", 'r')
|
37
|
+
end
|
38
|
+
|
39
|
+
def next_id
|
40
|
+
Dir.glob('db/revistas/*.yml').size + 1
|
41
|
+
end
|
42
|
+
|
43
|
+
def method_missing(name, *args, &block)
|
44
|
+
field = name.to_s.split('_').last
|
45
|
+
super if @fields.map(&:name).include? field
|
46
|
+
load_all.select do |object|
|
47
|
+
object.send(field) == args.first
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def load_all
|
54
|
+
Dir.glob('db/revistas/*.yml').map do |file|
|
55
|
+
deserialize file
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def deserialize(file)
|
60
|
+
YAML.load File.open(file, 'r')
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class Field
|
65
|
+
attr_reader :name, :required, :default
|
66
|
+
|
67
|
+
def initialize(name, required, default)
|
68
|
+
@name = name
|
69
|
+
@required = required
|
70
|
+
@default = default
|
71
|
+
end
|
72
|
+
|
73
|
+
def to_argument
|
74
|
+
"#{@name}: #{@default}"
|
75
|
+
end
|
76
|
+
|
77
|
+
def to_assign
|
78
|
+
"@#{@name} = #{@name}"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.included(base)
|
83
|
+
base.extend ClassMethods
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def serialize
|
89
|
+
YAML.dump self
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "my_active_file/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "my_active_file"
|
8
|
+
spec.version = MyActiveFile::VERSION
|
9
|
+
spec.authors = ["ewertonorg"]
|
10
|
+
spec.email = ["ewertonorg@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Just a file system database}
|
13
|
+
spec.description = %q{Just a file system database}
|
14
|
+
spec.files = Dir["{lib/**/*.rb,README.md,Rakefile,my_active_file.gemspec}"]
|
15
|
+
# dependência do código com a gem brnumeros
|
16
|
+
spec.add_dependency "brnumeros", "~> 3.3.0"
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: my_active_file
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ewertonorg
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-11-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: brnumeros
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.3.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.3.0
|
27
|
+
description: Just a file system database
|
28
|
+
email:
|
29
|
+
- ewertonorg@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- README.md
|
35
|
+
- Rakefile
|
36
|
+
- lib/my_active_file.rb
|
37
|
+
- lib/my_active_file/version.rb
|
38
|
+
- my_active_file.gemspec
|
39
|
+
homepage:
|
40
|
+
licenses: []
|
41
|
+
metadata: {}
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
requirements: []
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 2.7.7
|
59
|
+
signing_key:
|
60
|
+
specification_version: 4
|
61
|
+
summary: Just a file system database
|
62
|
+
test_files: []
|