class LessStruct

CHECK: LessStruct::Entity::Redis.check

LessStruct::Interactor::Simple

EG: LessStruct::Util::Hash.deep_stringify_keys({a:1})

EG: LessStruct::Util::String.to_snake(“Test::TestOne”) => “test/test_one” EG: LessStruct::Util::String.to_camel(“test/test_one”) => “Test::TestOne”

EG: LessStruct::Util::Hash.deep_stringify_keys({a:1})

Constants

VERSION

Public Class Methods

check() click to toggle source
# File lib/less_struct.rb, line 13
def check
  LessStruct::Check.call
end
new(*args) click to toggle source
# File lib/less_struct.rb, line 40
def initialize(*args)
  @base = ::OpenStruct.new(args_array_to_hash(*args))
end
use_debug_y() click to toggle source
# File lib/less_struct.rb, line 17
def use_debug_y
  @@use_debug_y ||= false
end
use_debug_y=(val) click to toggle source
# File lib/less_struct.rb, line 21
def use_debug_y=(val)
  @@use_debug_y = val
end
use_to_h_with_symbol_key_y() click to toggle source
# File lib/less_struct.rb, line 25
def use_to_h_with_symbol_key_y
  @@use_to_h_with_symbol_key_y ||= false
end
use_to_h_with_symbol_key_y=(val) click to toggle source
# File lib/less_struct.rb, line 29
def use_to_h_with_symbol_key_y=(val)
  @@use_to_h_with_symbol_key_y = val
end

Private Class Methods

instance() click to toggle source
# File lib/less_struct.rb, line 35
def instance
  @instance ||= new
end

Public Instance Methods

==(other) click to toggle source
# File lib/less_struct.rb, line 69
def ==(other)
  base == other.base
end
add(*args) click to toggle source
# File lib/less_struct.rb, line 73
def add(*args)
  args_array_to_hash(*args).each do |k, v|
    base[k] = v
  end
  self
end
base() click to toggle source
# File lib/less_struct.rb, line 44
def base
  @base
end
del(*args) click to toggle source
# File lib/less_struct.rb, line 80
def del(*args)
  args.each do |name|
    base.delete_field(name)
  end
  self
end
except(*args) click to toggle source
# File lib/less_struct.rb, line 93
def except(*args)
  args = args.map(&:to_s)
  klass.new(base.to_h.to_a.reject{ |o| args.include?(o[0].to_s) }.to_h)
end
freeze() click to toggle source
# File lib/less_struct.rb, line 102
def freeze
  base.freeze
  self
end
hash() click to toggle source
# File lib/less_struct.rb, line 107
def hash
  klass.hash ^ base.hash
end
inspect() click to toggle source
# File lib/less_struct.rb, line 64
def inspect
  content = "#{klass} #{base.to_h.map{|k, v| "#{k}=#{v.inspect}"}.join(', ')}".strip
  "#<#{content}>"
end
marshal_dump() click to toggle source
# File lib/less_struct.rb, line 111
def marshal_dump
  @base
end
marshal_load(base) click to toggle source
# File lib/less_struct.rb, line 115
def marshal_load(base)
  @base = base
end
optional() click to toggle source
# File lib/less_struct.rb, line 98
def optional
  base
end
slice(*args) click to toggle source
# File lib/less_struct.rb, line 87
def slice(*args)
  # klass.new(base.to_h.slice(*args))
  args = args.map(&:to_s)
  klass.new(base.to_h.to_a.select{ |o| args.include?(o[0].to_s) }.to_h)
end
to_h() click to toggle source
# File lib/less_struct.rb, line 48
def to_h
  unless klass.use_to_h_with_symbol_key_y
    LessStruct::Util::Hash.deep_stringify_keys(base.to_h)
  else
    base.to_h
  end
end
to_json(*args) click to toggle source
# File lib/less_struct.rb, line 56
def to_json(*args)
  to_h.to_json
end
to_s() click to toggle source
# File lib/less_struct.rb, line 60
def to_s
  inspect
end

Private Instance Methods

args_array_to_hash(*args) click to toggle source
# File lib/less_struct.rb, line 145
def args_array_to_hash(*args)
  args.first.respond_to?(:to_h) ? args.first.to_h : {}
end
klass() click to toggle source
# File lib/less_struct.rb, line 121
def klass
  self.class
end
method_missing(method_name, *args, &block) click to toggle source
# File lib/less_struct.rb, line 125
def method_missing(method_name, *args, &block)
  if respond_to_missing?(method_name)
    base.send(method_name, *args, &block)
  else
    raise_no_method_error(method_name)
  end
end
raise_no_method_error(method_name) click to toggle source
# File lib/less_struct.rb, line 141
def raise_no_method_error(method_name)
  raise NoMethodError, "undefined method `#{method_name}' for #{self.inspect}"
end
respond_to_missing?(method_name, include_private = false) click to toggle source
Calls superclass method
# File lib/less_struct.rb, line 133
def respond_to_missing?(method_name, include_private = false)
  super || base.respond_to?(method_name) || writer_method?(method_name)
end
writer_method?(method_name) click to toggle source
# File lib/less_struct.rb, line 137
def writer_method?(method_name)
  method_name.to_s.match?(/\A[^=]+=\z/)
end