gemmyrb 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 88d44792783df72bba22788805d9c9921a076e38
4
- data.tar.gz: 37b1cfe226df4006674b30f53c89b0376edde271
3
+ metadata.gz: 74c01cebf13722a15f5802d2d3264020e3dec979
4
+ data.tar.gz: 86990ea4e3d8bf73a8c0b8bbe99eb1923ca9e2be
5
5
  SHA512:
6
- metadata.gz: feb8fe730f9fcd32dd0ebfb5fc10e6fe3eeb58de5be37654d42d1adefb04bcc6c82a354803c33a841f85cf1af7ccfd13ead3fb902a6ac8ed872b34437d117c27
7
- data.tar.gz: 6dc21be406312cdc5a00d0a00c871d6b8bf3a8966d7d31a40df7e2f7724930257d18ed1682ff90d539f10a5df5746f7575dbc792be1d0258c3bf411f6f7298fd
6
+ metadata.gz: b81ed9ba77a689af77d892a1ef609c99d98a6c5a130e898f8fbb684d60908377046ee196ab1101b0227dfb8af5c39b4b90a2ab0cd0b7340cffbc21adf160c689
7
+ data.tar.gz: 95fcd4ba24e28536747f092f1711137414db55c9756fceacea866fa9b4369aafd24793ea79d7707fd0e98daa8e179d179b1046c548ba5c516323031730fb3144
data/lib/gemmy/cli.rb CHANGED
@@ -38,4 +38,11 @@ class Gemmy::CLI < Thor
38
38
  Gemmy::Tests.run
39
39
  end
40
40
 
41
+ # show version
42
+ #
43
+ desc "v", "version"
44
+ def v
45
+ puts Gemmy::VERSION
46
+ end
47
+
41
48
  end
@@ -3,6 +3,7 @@ class Gemmy::Components::Cache < Hash
3
3
  using Gemmy.patch("hash/i/persisted")
4
4
  using Gemmy.patch("hash/i/bury")
5
5
  using Gemmy.patch("object/i/home")
6
+ using Gemmy.patch("object/i/m")
6
7
 
7
8
  CachePath = ENV["GEMMY_CACHE_PATH"] || "#{home}/gemmy/caches"
8
9
 
@@ -10,9 +11,9 @@ class Gemmy::Components::Cache < Hash
10
11
  `mkdir -p #{CachePath}`
11
12
  end
12
13
 
13
- def initialize(db_name)
14
- @db = {}.persisted "#{CachePath}/#{db_name}.yaml"
15
- @memory = @db.get(:data)
14
+ def initialize(db_name, hash={})
15
+ @db = hash.persisted "#{CachePath}/#{db_name}.yaml"
16
+ @db.set_state hash
16
17
  end
17
18
 
18
19
  def get_or_set(*keys, &blk)
@@ -24,26 +25,32 @@ class Gemmy::Components::Cache < Hash
24
25
  result
25
26
  end
26
27
 
28
+ def data
29
+ @db.data
30
+ end
31
+
27
32
  def keys
28
33
  @db.data.keys
29
34
  end
30
35
 
31
- def get(*keys, source: :db)
32
- if source == :memory
33
- @memory.dig *keys
34
- elsif source == :db
35
- @db.dig *keys
36
- else
37
- raise ArgumentError
38
- end
36
+ def get(*keys)
37
+ @db.dig *keys
38
+ end
39
+
40
+ def set_state(hash)
41
+ @db.set_state hash
42
+ each_key &m(:delete)
43
+ deep_merge! hash
39
44
  end
40
45
 
41
46
  def set(*keys, val)
47
+ Gemmy.patch("hash/i/bury").bury(self, *keys, val)
42
48
  @db.set(*keys, val)
43
49
  end
44
50
 
45
51
  def clear
46
- # forwards it to PersistedHash
52
+ each_key &m(:delete)
47
53
  @db.clear
48
54
  end
55
+
49
56
  end
@@ -57,6 +57,40 @@ module Gemmy::Patches::HashPatch
57
57
  end
58
58
  end
59
59
 
60
+ module RecursiveMap
61
+ def recursive_map(&blk)
62
+ Gemmy.patch("hash/i/recursive_map").recursive_map(self, &blk)
63
+ end
64
+ def self.recursive_map(hash, &blk)
65
+ hash.reduce({}) do |result, (key, val)|
66
+ if val.is_a?(Hash)
67
+ result[key] = recursive_map(val, &blk)
68
+ else
69
+ result[key] = blk.call(bal)
70
+ end
71
+ result
72
+ end
73
+ end
74
+ end
75
+
76
+ module RecursiveKeys
77
+ # returns an array of arrays. Each sub-array is a list of keys.
78
+ # This list can be passed to Hash#dig with a splat operator.
79
+ def recursive_keys
80
+ Gemmy.patch("hash/i/recursive_keys").recursive_keys self
81
+ end
82
+ def self.recursive_keys hash
83
+ toplevel_keys = hash.keys.map &Array.method(:wrap)
84
+ toplevel_keys.map do |key_array|
85
+ if hash[key].is_a? Hash
86
+ key_array.concat recursive_keys hash[key]
87
+ else
88
+ key_array
89
+ end
90
+ end
91
+ end
92
+ end
93
+
60
94
  module Rekey
61
95
  # facets
62
96
  # rekey according to a block, i.e. {a: 1}.rekey &:to_s
@@ -205,10 +239,10 @@ module Gemmy::Patches::HashPatch
205
239
  #
206
240
  module Bury
207
241
  def bury *args
208
- Gemmy.patch("hash/i/bury")._bury self, *args
242
+ Gemmy.patch("hash/i/bury").bury self, *args
209
243
  end
210
244
  # The bury method, taking the input hash as a parameter
211
- def self._bury(caller_hash, *args)
245
+ def self.bury(caller_hash, *args)
212
246
  if args.count < 2
213
247
  raise ArgumentError.new("2 or more arguments required")
214
248
  elsif args.count == 2
@@ -216,7 +250,7 @@ module Gemmy::Patches::HashPatch
216
250
  else
217
251
  arg = args.shift
218
252
  caller_hash[arg] = {} unless caller_hash[arg]
219
- _bury(caller_hash[arg], *args) unless args.empty?
253
+ bury(caller_hash[arg], *args) unless args.empty?
220
254
  end
221
255
  caller_hash
222
256
  end
@@ -292,7 +326,7 @@ module Gemmy::Patches::HashPatch
292
326
  disk ? @store.transaction { @store[:data].dig(*keys) } : dig(*keys)
293
327
  end
294
328
  def set(*keys, val)
295
- bury = Gemmy::Patches::HashPatch::InstanceMethods::Bury.method(:_bury)
329
+ bury = Gemmy::Patches::HashPatch::InstanceMethods::Bury.method(:bury)
296
330
  bury.call(self, *keys, val)
297
331
  @store.transaction do
298
332
  bury.call(@store[:data], *(keys + [val]))
@@ -302,6 +336,12 @@ module Gemmy::Patches::HashPatch
302
336
  def data
303
337
  @store.transaction { @store[:data] }
304
338
  end
339
+
340
+ # This won't autovivify the hash automatically
341
+ def set_state(hash)
342
+ @store.transaction { @store[:data] = hash }
343
+ end
344
+
305
345
  def clear
306
346
  autovivified = Gemmy.patch("hash/i/autovivified")\
307
347
  .method(:_autovivified)
@@ -51,7 +51,7 @@ class Gemmy::Tasks::MakeGem
51
51
 
52
52
  attr_reader :name, :root_dir, :lib, :version_file, :main_file, :summary,
53
53
  :author, :email, :gemspec_file, :class_name, :rubygems_version,
54
- :gemfile
54
+ :gemfile, :url
55
55
 
56
56
  private
57
57
 
@@ -103,10 +103,7 @@ class Gemmy::Tasks::MakeGem
103
103
  def create_main_file
104
104
  @main_file = "#{lib}/#{name}.rb"
105
105
  main_text = <<-TXT.unindent
106
- require 'colored'
107
- require 'pry'
108
- require 'active_support/all'
109
- require 'thor'
106
+ require 'gemmy'
110
107
  module #{class_name}
111
108
  end
112
109
  Gem.find_files("#{name}/**/*.rb").each &method(:require)
@@ -123,6 +120,7 @@ class Gemmy::Tasks::MakeGem
123
120
  @summary = _prompt "add a one-line summary."
124
121
  @author = _prompt "enter the author's name"
125
122
  @email = _prompt "enter the author's email"
123
+ @url = _prompt "enter the homepage url"
126
124
  @rubygems_version = `gem -v`.chomp
127
125
  self
128
126
  end
@@ -144,15 +142,13 @@ class Gemmy::Tasks::MakeGem
144
142
  s.platform = Gem::Platform::RUBY
145
143
  s.authors = ["#{author}"]
146
144
  s.email = '#{email}'
147
- s.homepage = "http://github.com/maxpleaner/gemmy"
145
+ s.required_ruby_version = '~> 2.3'
146
+ s.homepage = "#{url}"
148
147
  s.files = Dir["lib/**/*.rb", "bin/*", "**/*.md", "LICENSE"]
149
148
  s.require_path = 'lib'
150
149
  s.required_rubygems_version = ">= #{rubygems_version}"
151
150
  s.executables = Dir["bin/*"].map &File.method(:basename)
152
- s.add_dependency "colored", '~> 1.2'
153
- s.add_dependency 'activesupport', '~> 4.2', '>= 4.2.7'
154
- s.add_dependency 'pry', '~> 0.10.4'
155
- s.add_dependency 'thor', '~> 0.19.4'
151
+ s.add_dependency 'gemmyrb'
156
152
  s.license = 'MIT'
157
153
  end
158
154
  TXT
data/lib/gemmy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Gemmy
2
- VERSION = '0.0.9'
2
+ VERSION = '0.1.0'
3
3
  end
data/lib/gemmy.rb CHANGED
@@ -45,10 +45,13 @@ class Gemmy
45
45
  .const_get(context_classname)
46
46
  .const_get method_name.camelcase
47
47
  end
48
+ singleton_class.send(:alias_method, :refinement, :patch)
49
+
48
50
 
49
51
  def self.patches(*args)
50
52
  Gemmy::Patches.class_refinements *args
51
53
  end
54
+ singleton_class.send(:alias_method, :refinements, :patches)
52
55
 
53
56
  # Get a constant,
54
57
  # lookup on Gemmy::Constants
@@ -86,12 +89,16 @@ class Gemmy
86
89
  end
87
90
  [components, core_patches].flatten
88
91
  end
92
+ singleton_class.send(:alias_method, :load, :load_globally)
89
93
  end
90
94
 
95
+
91
96
  Gem.find_files("gemmy/**/*.rb").sort_by do |x|
92
97
  x.split("/").length
93
98
  end.each &method(:require)
94
99
 
95
- # Alias for less typing
96
- class Gmy < Gemmy
100
+ unless ENV["NO_G_MODE"]
101
+ # Alias for less typing
102
+ class G < Gemmy
103
+ end
97
104
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gemmyrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - max pleaner
@@ -98,16 +98,16 @@ dependencies:
98
98
  name: sentence_interpreter
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - "~>"
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
- version: 0.0.7
103
+ version: '0'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - "~>"
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
- version: 0.0.7
110
+ version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: awesome_print
113
113
  requirement: !ruby/object:Gem::Requirement