lazy_lazer 0.3.0 → 0.3.1

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: a24047c46cd370e8fb1d092129dacb1816f50ebc
4
- data.tar.gz: 072b5a1b15857682e4317eb8f275685462199e3e
3
+ metadata.gz: 5ccb5b8a20cfa62e4ef74b7932724ef9c9f85629
4
+ data.tar.gz: 5f7ad225cf5db86c6bb46625e2738aa8bd547cf1
5
5
  SHA512:
6
- metadata.gz: de1fb716edf702586d593c085256d984ee3bd8cf0be8811381ac1d6eec10451146fa16f0e88f89a9561ad54d2242a255fc5351c1c6f0d961a2b01dc0e1c62f2d
7
- data.tar.gz: ada536d3a04d7ce62beff22a4e2afb1d1cf38bf1aa51cae3f08e1e2bed9f2848cecb42b5af8d047c4cea6a2260864749ee9ac5975748f525bbc51c72f29749c8
6
+ metadata.gz: 7846d9d05da36c2436f1a5b64005544dd1080d8515b0a1814d3a395288c3b5306c383fa163de03402a06f364a98ac58418ae0a6180f3e36f1b164e6aca56ee8e
7
+ data.tar.gz: eb973fec67fe6a6371c7ebd16bd67975dfab424068f87af1643b98ec8095fee98e31667b704523f4c57a2ff0b1c3be56474cd9f13ccfa016eadd2bf1870031d7
data/README.md CHANGED
@@ -1,11 +1,10 @@
1
- **lazy lazer**
2
-
3
- **features**:
4
- - simple codebase (~110 lines of code, ~200 lines of tests)
5
- - doesn't inherit all of the Hash and Enumerable cruft
6
- - super lazy, doesn't even parse attributes until it's necessary
1
+ <p align="center">
2
+ <img src="https://raw.githubusercontent.com/avinashbot/lazy_lazer/master/logo.png" width="500">
3
+ </p>
7
4
 
8
5
  ```ruby
6
+ require 'lazy_lazer'
7
+
9
8
  class User
10
9
  include LazyLazer
11
10
 
@@ -32,3 +31,14 @@ user.age #=> 21
32
31
  user.favorite_ice_cream #=> "chocolate"
33
32
  user.reload.favorite_ice_cream #=> "vanilla"
34
33
  ```
34
+
35
+ <p align="center">
36
+ licensed under
37
+ <a href="https://github.com/avinashbot/lazy_lazer/blob/master/LICENSE.txt">mit</a>
38
+ -
39
+ created for
40
+ <a href="https://github.com/avinashbot/redd">redd</a>
41
+ -
42
+ logo font is
43
+ <a href="https://www.behance.net/gallery/3588289/Zaguatica">zaguatica</a>
44
+ </p>
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LazyLazer
4
- VERSION = '0.3.0'
4
+ # The gem's semantic version number.
5
+ VERSION = '0.3.1'
5
6
  end
data/lib/lazy_lazer.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  require_relative 'lazy_lazer/version'
4
4
  require_relative 'lazy_lazer/errors'
5
5
 
6
- # LazyLazer
6
+ # The LazyLazer root that's included
7
7
  module LazyLazer
8
8
  # Hook into `include LazyLazer`.
9
9
  # @param [Module] base the object to include the methods in
@@ -22,8 +22,8 @@ module LazyLazer
22
22
  end
23
23
 
24
24
  # Get the source key from an instance
25
- # @param [Object] instance the instance
26
- # @param [Symbol] key the property key
25
+ # @param instance [Object] the instance
26
+ # @param key [Symbol] the property key
27
27
  # @return [Symbol] the source key if found or the passed key if not found
28
28
  def self.source_key(instance, key)
29
29
  instance.class.lazer_metadata[:from].fetch(key, key)
@@ -32,7 +32,7 @@ module LazyLazer
32
32
  # The methods to extend the class with.
33
33
  module ClassMethods
34
34
  # Copies parent properties into subclasses.
35
- # @param [Class] klass the subclass
35
+ # @param klass [Class] the subclass
36
36
  # @return [void]
37
37
  def inherited(klass)
38
38
  klass.instance_variable_set(:@lazer_metadata, @lazer_metadata)
@@ -44,8 +44,8 @@ module LazyLazer
44
44
  end
45
45
 
46
46
  # Define a property.
47
- # @param [Symbol] name the name of the property method
48
- # @param [Hash] options the options to create the property with
47
+ # @param name [Symbol] the name of the property method
48
+ # @param options [Hash] the options to create the property with
49
49
  # @option options [Boolean] :required (false) whether existence of this property should be
50
50
  # checked on model creation
51
51
  # @option options [Object, Proc] :default the default value to return if not provided
@@ -65,7 +65,7 @@ module LazyLazer
65
65
  # The methods to extend the instance with.
66
66
  module InstanceMethods
67
67
  # Create a new instance of the class from a set of source attributes.
68
- # @param [Hash] attributes the model attributes
68
+ # @param attributes [Hash] the model attributes
69
69
  # @return [void]
70
70
  def initialize(attributes = {})
71
71
  # Check that all required attributes exist.
@@ -79,7 +79,7 @@ module LazyLazer
79
79
  end
80
80
 
81
81
  # Converts all the attributes that haven't been converted yet and returns the final hash.
82
- # @param [Boolean] strict whether to fully load all attributes
82
+ # @param strict [Boolean] whether to fully load all attributes
83
83
  # @return [Hash] a hash representation of the model
84
84
  def to_h(strict = true)
85
85
  if strict
@@ -91,14 +91,13 @@ module LazyLazer
91
91
 
92
92
  # @abstract Provides reloading behaviour for lazy loading.
93
93
  # @return [Hash] the result of reloading the hash
94
- # @note if necessary, subclasses can make this method private, so this isn't tested.
95
94
  def lazer_reload
96
95
  self.fully_loaded = true
97
96
  {}
98
97
  end
99
98
 
100
99
  # Reload the object. Calls {#lazer_reload}, then merges the results into the internal store.
101
- # Also evicts the internal cache of the new keys.
100
+ # Also clears out the internal cache.
102
101
  # @return [self] the updated object
103
102
  def reload
104
103
  new_attributes = lazer_reload
@@ -108,7 +107,7 @@ module LazyLazer
108
107
  end
109
108
 
110
109
  # Return the value of the attribute.
111
- # @param [Symbol] name the attribute name
110
+ # @param name [Symbol] the attribute name
112
111
  # @raise MissingAttribute if the key was not found
113
112
  def read_attribute(name)
114
113
  # Returns the cached attribute.
@@ -150,7 +149,7 @@ module LazyLazer
150
149
  end
151
150
 
152
151
  # Return the value of the attribute, returning nil if not found
153
- # @param [Symbol] name the attribute name
152
+ # @param name [Symbol] the attribute name
154
153
  def [](name)
155
154
  read_attribute(name)
156
155
  rescue MissingAttribute
@@ -158,14 +157,14 @@ module LazyLazer
158
157
  end
159
158
 
160
159
  # Update an attribute.
161
- # @param [Symbol] attribute the attribute to update
160
+ # @param attribute [Symbol] the attribute to update
162
161
  # @param [Object] value the new value
163
162
  def write_attribute(attribute, value)
164
163
  @_lazer_cache[attribute] = value
165
164
  end
166
165
 
167
166
  # Update multiple attributes at once.
168
- # @param [Hash<Symbol, Object>] new_attributes the new attributes
167
+ # @param new_attributes [Hash<Symbol, Object>] the new attributes
169
168
  def assign_attributes(new_attributes)
170
169
  new_attributes.each { |key, value| write_attribute(key, value) }
171
170
  end
@@ -178,7 +177,7 @@ module LazyLazer
178
177
 
179
178
  private
180
179
 
181
- # @param [Boolean] state the new state
180
+ # @param state [Boolean] the new state
182
181
  def fully_loaded=(state)
183
182
  @_lazer_fully_loaded = state
184
183
  end
data/logo.png ADDED
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lazy_lazer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Avinash Dwarapu
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-20 00:00:00.000000000 Z
11
+ date: 2017-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -131,6 +131,7 @@ files:
131
131
  - lib/lazy_lazer.rb
132
132
  - lib/lazy_lazer/errors.rb
133
133
  - lib/lazy_lazer/version.rb
134
+ - logo.png
134
135
  homepage: https://github.com/avinashbot/lazy_lazer
135
136
  licenses:
136
137
  - MIT